Skip to content

Commit d8c4c22

Browse files
minor #40809 Improve deprecation message for session (jderusse)
This PR was merged into the 5.3-dev branch. Discussion ---------- Improve deprecation message for session | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - The `session` service is not public since we deprecate it, which lead to headache when people migrate to 5.3: When people expect the service to be public (like in tests), the service does not exist anymore (removed or inlined), it's now an alias to `.session.do-not-use` and deprecation telling how to migrate has not been triggered because the service has been removed / inlined. This PR makes the `session` service/alias public, and also improves the deprecation message a little bit. /cc @javiereguiluz , @wouterj Commits ------- b568768cec Improvide deprecation message for session
2 parents 1126e21 + 4682ce9 commit d8c4c22

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

DependencyInjection/Compiler/SessionPass.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,22 @@ public function process(ContainerBuilder $container)
2626
return;
2727
}
2828

29-
// BC layer: Make "session" an alias of ".session.do-not-use" when not overriden by the user
29+
// BC layer: Make "session" an alias of ".session.do-not-use" when not overridden by the user
3030
if (!$container->has('session')) {
3131
$alias = $container->setAlias('session', '.session.do-not-use');
32-
$alias->setDeprecated('symfony/framework-bundle', '5.3', 'The "%alias_id%" service is deprecated, use "$requestStack->getSession()" instead.');
32+
$alias->setDeprecated('symfony/framework-bundle', '5.3', 'The "%alias_id%" service and "SessionInterface" alias are deprecated, use "$requestStack->getSession()" instead.');
33+
// restore previous behavior
34+
$alias->setPublic(true);
3335

3436
return;
3537
}
3638

3739
if ($container->hasDefinition('session')) {
3840
$definition = $container->getDefinition('session');
39-
$definition->setDeprecated('symfony/framework-bundle', '5.3', 'The "%service_id%" service is deprecated, use "$requestStack->getSession()" instead.');
41+
$definition->setDeprecated('symfony/framework-bundle', '5.3', 'The "%service_id%" service and "SessionInterface" alias are deprecated, use "$requestStack->getSession()" instead.');
4042
} else {
4143
$alias = $container->getAlias('session');
42-
$alias->setDeprecated('symfony/framework-bundle', '5.3', 'The "%alias_id%" alias is deprecated, use "$requestStack->getSession()" instead.');
44+
$alias->setDeprecated('symfony/framework-bundle', '5.3', 'The "%alias_id%" and "SessionInterface" aliases are deprecated, use "$requestStack->getSession()" instead.');
4345
$definition = $container->findDefinition('session');
4446
}
4547

Resources/config/session.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
->set('.session.deprecated', SessionInterface::class) // to be removed in 6.0
8989
->factory([inline_service(DeprecatedSessionFactory::class)->args([service('request_stack')]), 'getSession'])
9090
->alias(SessionInterface::class, '.session.do-not-use')
91-
->deprecate('symfony/framework-bundle', '5.3', 'The "%alias_id%" alias is deprecated, use "$requestStack->getSession()" instead.')
91+
->deprecate('symfony/framework-bundle', '5.3', 'The "%alias_id%" and "SessionInterface" aliases are deprecated, use "$requestStack->getSession()" instead.')
9292
->alias(SessionStorageInterface::class, 'session.storage')
9393
->deprecate('symfony/framework-bundle', '5.3', 'The "%alias_id%" alias is deprecated, use "session.storage.factory" instead.')
9494
->alias(\SessionHandlerInterface::class, 'session.handler')

Session/DeprecatedSessionFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(RequestStack $requestStack)
3535

3636
public function getSession(): ?SessionInterface
3737
{
38-
trigger_deprecation('symfony/framework-bundle', '5.3', 'The "session" service is deprecated, use "$requestStack->getSession()" instead.');
38+
trigger_deprecation('symfony/framework-bundle', '5.3', 'The "session" service and "SessionInterface" alias are deprecated, use "$requestStack->getSession()" instead.');
3939

4040
try {
4141
return $this->requestStack->getSession();

Tests/Functional/SessionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function testFlashOnInjectedFlashbag($config, $insulate)
105105
*/
106106
public function testSessionServiceTriggerDeprecation($config, $insulate)
107107
{
108-
$this->expectDeprecation('Since symfony/framework-bundle 5.3: The "session" service is deprecated, use "$requestStack->getSession()" instead.');
108+
$this->expectDeprecation('Since symfony/framework-bundle 5.3: The "session" service and "SessionInterface" alias are deprecated, use "$requestStack->getSession()" instead.');
109109

110110
$client = $this->createClient(['test_case' => 'Session', 'root_config' => $config]);
111111
if ($insulate) {

0 commit comments

Comments
 (0)