Improvide deprecation message for session

This commit is contained in:
Jérémy Derussé 2021-04-13 22:31:53 +02:00
parent 0f96ac7484
commit b568768cec
No known key found for this signature in database
GPG Key ID: 2083FA5758C473D2
4 changed files with 9 additions and 7 deletions

View File

@ -26,20 +26,22 @@ class SessionPass implements CompilerPassInterface
return; 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')) { if (!$container->has('session')) {
$alias = $container->setAlias('session', '.session.do-not-use'); $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; return;
} }
if ($container->hasDefinition('session')) { if ($container->hasDefinition('session')) {
$definition = $container->getDefinition('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 { } else {
$alias = $container->getAlias('session'); $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'); $definition = $container->findDefinition('session');
} }

View File

@ -88,7 +88,7 @@ return static function (ContainerConfigurator $container) {
->set('.session.deprecated', SessionInterface::class) // to be removed in 6.0 ->set('.session.deprecated', SessionInterface::class) // to be removed in 6.0
->factory([inline_service(DeprecatedSessionFactory::class)->args([service('request_stack')]), 'getSession']) ->factory([inline_service(DeprecatedSessionFactory::class)->args([service('request_stack')]), 'getSession'])
->alias(SessionInterface::class, '.session.do-not-use') ->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') ->alias(SessionStorageInterface::class, 'session.storage')
->deprecate('symfony/framework-bundle', '5.3', 'The "%alias_id%" alias is deprecated, use "session.storage.factory" instead.') ->deprecate('symfony/framework-bundle', '5.3', 'The "%alias_id%" alias is deprecated, use "session.storage.factory" instead.')
->alias(\SessionHandlerInterface::class, 'session.handler') ->alias(\SessionHandlerInterface::class, 'session.handler')

View File

@ -35,7 +35,7 @@ class DeprecatedSessionFactory
public function getSession(): ?SessionInterface 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 { try {
return $this->requestStack->getSession(); return $this->requestStack->getSession();

View File

@ -105,7 +105,7 @@ class SessionTest extends AbstractWebTestCase
*/ */
public function testSessionServiceTriggerDeprecation($config, $insulate) 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]); $client = $this->createClient(['test_case' => 'Session', 'root_config' => $config]);
if ($insulate) { if ($insulate) {