Skip to content

Commit 5f7e029

Browse files
committed
Merge branch '4.4'
* 4.4: [HttpFoundation][FrameworkBundle] allow configuring the session handler with a DSN [Validator] Add AutoMapping constraint to enable or disable auto-validation [DI] Fix "!tagged" related upgrade/changelog notes
2 parents 13dd680 + 8be37e7 commit 5f7e029

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ CHANGELOG
3838
* Added sort option for `translation:update` command.
3939
* [BC Break] The `framework.messenger.routing.senders` config key is not deep merged anymore.
4040
* Added `secrets:*` commands and `%env(secret:...)%` processor to deal with secrets seamlessly.
41+
* Made `framework.session.handler_id` accept a DSN
4142

4243
4.3.0
4344
-----

DependencyInjection/FrameworkExtension.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ public function load(array $configs, ContainerBuilder $container)
248248
}
249249
}
250250

251+
// register cache before session so both can share the connection services
252+
$this->registerCacheConfiguration($config['cache'], $container);
253+
251254
if ($this->isConfigEnabled($container, $config['session'])) {
252255
if (!\extension_loaded('session')) {
253256
throw new LogicException('Session support cannot be enabled as the session extension is not installed. See https://php.net/session.installation for instructions.');
@@ -328,7 +331,6 @@ public function load(array $configs, ContainerBuilder $container)
328331
$this->registerFragmentsConfiguration($config['fragments'], $container, $loader);
329332
$this->registerTranslatorConfiguration($config['translator'], $container, $loader, $config['default_locale']);
330333
$this->registerProfilerConfiguration($config['profiler'], $container, $loader);
331-
$this->registerCacheConfiguration($config['cache'], $container);
332334
$this->registerWorkflowConfiguration($config['workflows'], $container, $loader);
333335
$this->registerDebugConfiguration($config['php_errors'], $container, $loader);
334336
$this->registerRouterConfiguration($config['router'], $container, $loader);
@@ -902,7 +904,18 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
902904
$container->getDefinition('session.storage.native')->replaceArgument(1, null);
903905
$container->getDefinition('session.storage.php_bridge')->replaceArgument(0, null);
904906
} else {
905-
$container->setAlias('session.handler', $config['handler_id'])->setPrivate(true);
907+
$container->resolveEnvPlaceholders($config['handler_id'], null, $usedEnvs);
908+
909+
if ($usedEnvs || preg_match('#^[a-z]++://#', $config['handler_id'])) {
910+
$id = '.cache_connection.'.ContainerBuilder::hash($config['handler_id']);
911+
912+
$container->getDefinition('session.abstract_handler')
913+
->replaceArgument(0, $container->hasDefinition($id) ? new Reference($id) : $config['handler_id']);
914+
915+
$container->setAlias('session.handler', 'session.abstract_handler')->setPrivate(true);
916+
} else {
917+
$container->setAlias('session.handler', $config['handler_id'])->setPrivate(true);
918+
}
906919
}
907920

908921
$container->setParameter('session.save_path', $config['save_path']);

Resources/config/session.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@
5656
</argument>
5757
</service>
5858

59+
<service id="session.abstract_handler" class="Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler">
60+
<factory class="Symfony\Component\HttpFoundation\Session\Storage\Handler\SessionHandlerFactory" method="createHandler" />
61+
<argument />
62+
</service>
63+
5964
<service id="session_listener" class="Symfony\Component\HttpKernel\EventListener\SessionListener">
6065
<tag name="kernel.event_subscriber" />
6166
<argument type="service_locator">

0 commit comments

Comments
 (0)