From b568768cec8c6b422731b16cbeace5342244d69f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Tue, 13 Apr 2021 22:31:53 +0200 Subject: [PATCH] Improvide deprecation message for session --- .../DependencyInjection/Compiler/SessionPass.php | 10 ++++++---- .../FrameworkBundle/Resources/config/session.php | 2 +- .../Session/DeprecatedSessionFactory.php | 2 +- .../FrameworkBundle/Tests/Functional/SessionTest.php | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/SessionPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/SessionPass.php index c0c9dd6758..7230fc9fb4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/SessionPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/SessionPass.php @@ -26,20 +26,22 @@ class SessionPass implements CompilerPassInterface return; } - // BC layer: Make "session" an alias of ".session.do-not-use" when not overriden by the user + // BC layer: Make "session" an alias of ".session.do-not-use" when not overridden by the user if (!$container->has('session')) { $alias = $container->setAlias('session', '.session.do-not-use'); - $alias->setDeprecated('symfony/framework-bundle', '5.3', 'The "%alias_id%" service is deprecated, use "$requestStack->getSession()" instead.'); + $alias->setDeprecated('symfony/framework-bundle', '5.3', 'The "%alias_id%" service and "SessionInterface" alias are deprecated, use "$requestStack->getSession()" instead.'); + // restore previous behavior + $alias->setPublic(true); return; } if ($container->hasDefinition('session')) { $definition = $container->getDefinition('session'); - $definition->setDeprecated('symfony/framework-bundle', '5.3', 'The "%service_id%" service is deprecated, use "$requestStack->getSession()" instead.'); + $definition->setDeprecated('symfony/framework-bundle', '5.3', 'The "%service_id%" service and "SessionInterface" alias are deprecated, use "$requestStack->getSession()" instead.'); } else { $alias = $container->getAlias('session'); - $alias->setDeprecated('symfony/framework-bundle', '5.3', 'The "%alias_id%" alias is deprecated, use "$requestStack->getSession()" instead.'); + $alias->setDeprecated('symfony/framework-bundle', '5.3', 'The "%alias_id%" and "SessionInterface" aliases are deprecated, use "$requestStack->getSession()" instead.'); $definition = $container->findDefinition('session'); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.php index bef83c3c01..9dbaff5c82 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.php @@ -88,7 +88,7 @@ return static function (ContainerConfigurator $container) { ->set('.session.deprecated', SessionInterface::class) // to be removed in 6.0 ->factory([inline_service(DeprecatedSessionFactory::class)->args([service('request_stack')]), 'getSession']) ->alias(SessionInterface::class, '.session.do-not-use') - ->deprecate('symfony/framework-bundle', '5.3', 'The "%alias_id%" alias is deprecated, use "$requestStack->getSession()" instead.') + ->deprecate('symfony/framework-bundle', '5.3', 'The "%alias_id%" and "SessionInterface" aliases are deprecated, use "$requestStack->getSession()" instead.') ->alias(SessionStorageInterface::class, 'session.storage') ->deprecate('symfony/framework-bundle', '5.3', 'The "%alias_id%" alias is deprecated, use "session.storage.factory" instead.') ->alias(\SessionHandlerInterface::class, 'session.handler') diff --git a/src/Symfony/Bundle/FrameworkBundle/Session/DeprecatedSessionFactory.php b/src/Symfony/Bundle/FrameworkBundle/Session/DeprecatedSessionFactory.php index c2c1cd34ae..faa29a1c7e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Session/DeprecatedSessionFactory.php +++ b/src/Symfony/Bundle/FrameworkBundle/Session/DeprecatedSessionFactory.php @@ -35,7 +35,7 @@ class DeprecatedSessionFactory public function getSession(): ?SessionInterface { - trigger_deprecation('symfony/framework-bundle', '5.3', 'The "session" service is deprecated, use "$requestStack->getSession()" instead.'); + trigger_deprecation('symfony/framework-bundle', '5.3', 'The "session" service and "SessionInterface" alias are deprecated, use "$requestStack->getSession()" instead.'); try { return $this->requestStack->getSession(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php index 5140604793..7d66ff1726 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php @@ -105,7 +105,7 @@ class SessionTest extends AbstractWebTestCase */ public function testSessionServiceTriggerDeprecation($config, $insulate) { - $this->expectDeprecation('Since symfony/framework-bundle 5.3: The "session" service is deprecated, use "$requestStack->getSession()" instead.'); + $this->expectDeprecation('Since symfony/framework-bundle 5.3: The "session" service and "SessionInterface" alias are deprecated, use "$requestStack->getSession()" instead.'); $client = $this->createClient(['test_case' => 'Session', 'root_config' => $config]); if ($insulate) {