Skip to content

Commit 09c97bd

Browse files
committed
bug #37572 [FrameworkBundle] set default session.handler alias if handler_id is not provided (Youssef BENHSSAIEN)
This PR was squashed before being merged into the 3.4 branch. Discussion ---------- [FrameworkBundle] set default session.handler alias if handler_id is not provided | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #37245 | License | MIT | Doc PR | Without a configured [`handler_id`](https://symfony.com/doc/current/session.html#configuration), the `session.handler` alias is not created, and somes services depend on this alias specialy. Related to the reported issue above (affected version 4.4.9), the `ServiceHandlerInterface` is an alias of `session.handler`, when execute : - `bin/console debug:container session.handler` : The alias is not defined, so the `ContainerDebugCommand` look for a service containing the `session.handler` as part of his name (ContainerDebugCommand::findServiceIdsContaining() is called and returns by default `session.handler.native_file`) - `bin/console debug:container SessionHandlerInterface` : The service is defined as an alias of `session.handler`, when calling `ContainerBuilder::getDefinition('session.handler')` the exception occured as the alias is not defined. # Implemented solution Create a default `session.handler` when the param `handler_id` is not provided (I choosed `session.handler.native_file` rather than `NullSessionHandler`). # Affected versions From [`3.4`](https://github.com/symfony/framework-bundle/blob/3.4/DependencyInjection/FrameworkExtension.php#L879) to [`5.1`](https://github.com/symfony/framework-bundle/blob/5.1/DependencyInjection/FrameworkExtension.php#L955) Commits ------- 46c8c37 [FrameworkBundle] set default session.handler alias if handler_id is not provided
2 parents 87a5135 + 46c8c37 commit 09c97bd

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,7 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
880880
// Set the handler class to be null
881881
$container->getDefinition('session.storage.native')->replaceArgument(1, null);
882882
$container->getDefinition('session.storage.php_bridge')->replaceArgument(0, null);
883+
$container->setAlias('session.handler', 'session.handler.native_file')->setPrivate(true);
883884
} else {
884885
$container->setAlias('session.handler', $config['handler_id'])->setPrivate(true);
885886
}

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ public function testNullSessionHandler()
463463
$this->assertTrue($container->hasDefinition('session'), '->registerSessionConfiguration() loads session.xml');
464464
$this->assertNull($container->getDefinition('session.storage.native')->getArgument(1));
465465
$this->assertNull($container->getDefinition('session.storage.php_bridge')->getArgument(0));
466+
$this->assertEquals('session.handler.native_file', (string) $container->getAlias('session.handler'));
466467
}
467468

468469
public function testRequest()

0 commit comments

Comments
 (0)