10000 Remove deprecate session service · symfony/symfony@fd9cff3 · GitHub
[go: up one dir, main page]

Skip to content

Commit fd9cff3

Browse files
committed
Remove deprecate session service
1 parent d9f0467 commit fd9cff3

File tree

42 files changed

+142
-676
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+142
-676
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ CHANGELOG
44
6.0
55
---
66

7+
* Remove the `session.storage` alias and `session.storage.*` services, use the `session.storage.factory` alias and `session.storage.factory.*` services instead
8+
* Remove `framework.session.storage_id` configuration option, use the `framework.session.storage_factory_id` configuration option instead
9+
* Remove the `session` service and the `SessionInterface` alias, use the `\Symfony\Component\HttpFoundation\Request::getSession()` or the new `\Symfony\Component\HttpFoundation\RequestStack::getSession()` methods instead
10+
* Remove the `session.attribute_bag` service and `session.flash_bag` service
711
* Remove the `lock.RESOURCE_NAME` and `lock.RESOURCE_NAME.store` services and the `lock`, `LockInterface`, `lock.store` and `PersistingStoreInterface` aliases, use `lock.RESOURCE_NAME.factory`, `lock.factory` or `LockFactory` instead
812
* The `form.factory`, `form.type.file`, `translator`, `security.csrf.token_manager`, `serializer`,
913
`cache_clearer`, `filesystem` and `validator` services are now private

src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php

-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
use Symfony\Component\HttpFoundation\RequestStack;
3030
use Symfony\Component\HttpFoundation\Response;
3131
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
32-
use Symfony\Component\HttpFoundation\Session\SessionInterface;
3332
use Symfony\Component\HttpFoundation\StreamedResponse;
3433
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
3534
use Symfony\Component\HttpKernel\HttpKernelInterface;
@@ -94,7 +93,6 @@ public static function getSubscribedServices()
9493
'request_stack' => '?'.RequestStack::class,
9594
'http_kernel' => '?'.HttpKernelInterface::class,
9695
'serializer' => '?'.SerializerInterface::class,
97-
'session' => '?'.SessionInterface::class,
9896
'security.authorization_checker' => '?'.AuthorizationCheckerInterface::class,
9997
'twig' => '?'.Environment::class,
10098
'doctrine' => '?'.ManagerRegistry::class,

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/SessionPass.php

-72
This file was deleted.

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

+1-8
Original file line numberDiff line numberDiff line change
@@ -612,15 +612,8 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
612612
->arrayNode('session')
613613
->info('session configuration')
614614
->canBeEnabled()
615-
->beforeNormalization()
616-
->ifTrue(function ($v) {
617-
return \is_array($v) && isset($v['storage_id']) && isset($v['storage_factory_id']);
618-
})
619-
->thenInvalid('You cannot use both "storage_id" and "storage_factory_id" at the same time under "framework.session"')
620-
->end()
621615
->children()
622-
->scalarNode('storage_id')->defaultValue('session.storage.native')->end()
623-
->scalarNode('storage_factory_id')->defaultNull()->end()
616+
->scalarNode('storage_factory_id')->defaultValue('session.storage.factory.native')->end()
624617
->scalarNode('handler_id')->defaultValue('session.handler.native_file')->end()
625618
->scalarNode('name')
626619
->validate()

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

+8-33
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,14 @@
7272
use Symfony\Component\HttpClient\RetryableHttpClient;
7373
use Symfony\Component\HttpClient\ScopingHttpClient;
7474
use Symfony\Component\HttpFoundation\Request; F438
75-
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
7675
use Symfony\Component\HttpKernel\Attribute\AsController;
7776
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
7877
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
7978
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
8079
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
8180
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
81+
use Symfony\Component\HttpKernel\EventListener\AbstractTestSessionListener;
82+
use Symfony\Component\HttpKernel\EventListener\TestSessionListener;
8283
use Symfony\Component\Lock\Lock;
8384
use Symfony\Component\Lock\LockFactory;
8485
use Symfony\Component\Lock\PersistingStoreInterface;
@@ -318,7 +319,7 @@ public function load(array $configs, ContainerBuilder $container)
318319
$this->sessionConfigEnabled = true;
319320
$this->registerSessionConfiguration($config['session'], $container, $loader);
320321
if (!empty($config['test'])) {
321-
$container->getDefinition('test.session.listener')->setArgument(1, '%session.storage.options%');
322+
$container->getDefinition('test.session.listener')->setArgument(method_exists(TestSessionListener::class, 'getSession') ? 1 : 0, '%session.storage.options%');
322323
}
323324
}
324325

@@ -1041,20 +1042,7 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
10411042
$loader->load('session.php');
10421043

10431044
// session storage
1044-
if (null === $config['storage_factory_id']) {
1045-
trigger_deprecation('symfony/framework-bundle', '5.3', 'Not setting the "framework.session.storage_factory_id" configuration option is deprecated, it will default to "session.storage.factory.native" and will replace the "framework.session.storage_id" configuration option in version 6.0.');
1046-
$container->setAlias('session.storage', $config['storage_id']);
1047-
$container->setAlias('session.storage.factory', 'session.storage.factory.service');
1048-
} else {
1049-
$container->setAlias('session.storage.factory', $config['storage_factory_id']);
1050-
1051-
$container->removeAlias(SessionStorageInterface::class);
1052-
$container->removeDefinition('session.storage.metadata_bag');
1053-
$container->removeDefinition('session.storage.native');
1054-
$container->removeDefinition('session.storage.php_bridge');
1055-
$container->removeDefinition('session.storage.mock_file');
1056-
$container->removeAlias('session.storage.filesystem');
1057-
}
1045+
$container->setAlias('session.storage.factory', $config['storage_factory_id']);
10581046

10591047
$options = ['cache_limiter' => '0'];
10601048
foreach (['name', 'cookie_lifetime', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'cookie_samesite', 'use_cookies', 'gc_maxlifetime', 'gc_probability', 'gc_divisor', 'sid_length', 'sid_bits_per_character'] as $key) {
@@ -1064,30 +1052,17 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
10641052
}
10651053

10661054
if ('auto' === ($options['cookie_secure'] ?? null)) {
1067-
if (null === $config['storage_factory_id']) {
1068-
$locator = $container->getDefinition('session_listener')->getArgument(0);
1069-
$locator->setValues($locator->getValues() + [
1070-
'session_storage' => new Reference('session.storage', ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
1071-
'request_stack' => new Reference('request_stack'),
1072-
]);
1073-
} else {
1074-
$container->getDefinition('session.storage.factory.native')->replaceArgument(3, true);
1075-
$container->getDefinition('session.storage.factory.php_bridge')->replaceArgument(2, true);
1076-
}
1055+
$container->getDefinition('session.storage.factory.native')->replaceArgument(3, true);
1056+
$container->getDefinition('session.storage.factory.php_bridge')->replaceArgument(2, true);
10771057
}
10781058

10791059
$container->setParameter('session.storage.options', $options);
10801060

10811061
// session handler (the internal callback registered with PHP session management)
10821062
if (null === $config['handler_id']) {
10831063
// Set the handler class to be null
1084-
if ($container->hasDefinition('session.storage.native')) {
1085-
$container->getDefinition('session.storage.native')->replaceArgument(1, null);
1086-
$container->getDefinition('session.storage.php_bridge')->replaceArgument(0, null);
1087-
} else {
1088-
$container->getDefinition('session.storage.factory.native')->replaceArgument(1, null);
1089-
$container->getDefinition('session.storage.factory.php_bridge')->replaceArgument(0, null);
1090-
}
1064+
$container->getDefinition('session.storage.factory.native')->replaceArgument(1, null);
1065+
$container->getDefinition('session.storage.factory.php_bridge')->replaceArgument(0, null);
10911066

10921067
$container->setAlias('session.handler', 'session.handler.native_file');
10931068
} else {

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
2121
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
2222
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RemoveUnusedSessionMarshallingHandlerPass;
23-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SessionPass;
2423
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerRealRefPass;
2524
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerWeakRefPass;
2625
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
@@ -159,7 +158,6 @@ public function build(ContainerBuilder $container)
159158
$container->addCompilerPass(new RegisterReverseContainerPass(true));
160159
$container->addCompilerPass(new RegisterReverseContainerPass(false), PassConfig::TYPE_AFTER_REMOVING);
161160
$container->addCompilerPass(new RemoveUnusedSessionMarshallingHandlerPass());
162-
$container->addCompilerPass(new SessionPass());
163161

164162
if ($container->getParameter('kernel.debug')) {
165163
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 2);

src/Symfony/Bundle/FrameworkBundle/Resources/config/session.php

-70
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,23 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1313

14-
use Symfony\Bundle\FrameworkBundle\Session\DeprecatedSessionFactory;
15-
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
16-
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
17-
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
18-
use Symfony\Component\HttpFoundation\Session\Session;
1914
use Symfony\Component\HttpFoundation\Session\SessionFactory;
20-
use Symfony\Component\HttpFoundation\Session\SessionInterface;
2115
use Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler;
2216
use Symfony\Component\HttpFoundation\Session\Storage\Handler\IdentityMarshaller;
2317
use Symfony\Component\HttpFoundation\Session\Storage\Handler\MarshallingSessionHandler;
2418
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler;
2519
use Symfony\Component\HttpFoundation\Session\Storage\Handler\SessionHandlerFactory;
2620
use Symfony\Component\HttpFoundation\Session\Storage\Handler\StrictSessionHandler;
2721
use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
28-
use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage;
2922
use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorageFactory;
30-
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
3123
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorageFactory;
32-
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage;
3324
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorageFactory;
34-
use Symfony\Component\HttpFoundation\Session\Storage\ServiceSessionFactory;
35-
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
3625
use Symfony\Component\HttpKernel\EventListener\SessionListener;
3726

3827
return static function (ContainerConfigurator $container) {
3928
$container->parameters()->set('session.metadata.storage_key', '_sf2_meta');
4029

4130
$container->services()
42-
->set('.session.do-not-use', Session::class) // to be removed in 6.0
43-
->factory([service('session.factory'), 'createSession'])
4431
->set('session.factory', SessionFactory::class)
4532
->args([
4633
service('request_stack'),
@@ -79,60 +66,9 @@
7966
param('session.metadata.update_threshold'),
8067
]),
8168
])
82-
->set('session.storage.factory.service', ServiceSessionFactory::class)
83-
->args([
84-
service('session.storage'),
85-
])
86-
->deprecate('symfony/framework-bundle', '5.3', 'The "%service_id%" service is deprecated, use "session.storage.factory.native", "session.storage.factory.php_bridge" or "session.storage.factory.mock_file" instead.')
8769

88-
->set('.session.deprecated', SessionInterface::class) // to be removed in 6.0
89-
->factory([inline_service(DeprecatedSessionFactory::class)->args([service('request_stack')]), 'getSession'])
90-
->alias(SessionInterface::class, '.session.do-not-use')
91-
->deprecate('symfony/framework-bundle', '5.3', 'The "%alias_id%" and "SessionInterface" aliases are deprecated, use "$requestStack->getSession()" instead.')
92-
->alias(SessionStorageInterface::class, 'session.storage')
93-
->deprecate('symfony/framework-bundle', '5.3', 'The "%alias_id%" alias is deprecated, use "session.storage.factory" instead.')
9470
->alias(\SessionHandlerInterface::class, 'session.handler')
9571

96-
->set('session.storage.metadata_bag', MetadataBag::class)
97-
->args([
98-
param('session.metadata.storage_key'),
99-
param('session.metadata.update_threshold'),
100-
])
101-
->deprecate('symfony/framework-bundle', '5.3', 'The "%service_id%" service is deprecated, create your own "session.storage.factory" instead.')
102-
103-
->set('session.storage.native', NativeSessionStorage::class)
104-
->args([
105-
param('session.storage.options'),
106-
service('session.handler'),
107-
service('session.storage.metadata_bag'),
108-
])
109-
->deprecate('symfony/framework-bundle', '5.3', 'The "%service_id%" service is deprecated, use "session.storage.factory.native" instead.')
110-
111-
->set('session.storage.php_bridge', PhpBridgeSessionStorage::class)
112-
->args([
113-
service('session.handler'),
114-
service('session.storage.metadata_bag'),
115-
])
116-
->deprecate('symfony/framework-bundle', '5.3', 'The "%service_id%" service is deprecated, use "session.storage.factory.php_bridge" instead.')
117-
118-
->set('session.flash_bag', FlashBag::class)
119-
->factory([service('.session.do-not-use'), 'getFlashBag'])
120-
->deprecate('symfony/framework-bundle', '5.1', 'The "%service_id%" service is deprecated, use "$session->getFlashBag()" instead.')
121-
->alias(FlashBagInterface::class, 'session.flash_bag')
122-
123-
->set('session.attribute_bag', AttributeBag::class)
124-
->factory([service('.session.do-not-use'), 'getBag'])
125-
->args(['attributes'])
126-
->deprecate('symfony/framework-bundle', '5.1', 'The "%service_id%" service is deprecated, use "$session->getAttributeBag()" instead.')
127-
128-
->set('session.storage.mock_file', MockFileSessionStorage::class)
129-
->args([
130-
param('kernel.cache_dir').'/sessions',
131-
'MOCKSESSID',
132-
service('session.storage.metadata_bag'),
133-
])
134-
->deprecate('symfony/framework-bundle', '5.3', 'The "%service_id%" service is deprecated, use "session.storage.factory.mock_file" instead.')
135-
13672
->set('session.handler.native_file', StrictSessionHandler::class)
13773
->args([
13874
inline_service(NativeFileSessionHandler::class)
@@ -147,19 +83,13 @@
14783
->args([
14884
service_locator([
14985
'session_factory' => service('session.factory')->ignoreOnInvalid(),
150-
'session' => service('.session.do-not-use')->ignoreOnInvalid(),
151-
'initialized_session' => service('.session.do-not-use')->ignoreOnUninitialized(),
15286
'logger' => service('logger')->ignoreOnInvalid(),
15387
'session_collector' => service('data_collector.request.session_collector')->ignoreOnInvalid(),
15488
]),
15589
param('kernel.debug'),
15690
])
15791
->tag('kernel.event_subscriber')
15892

159-
// for BC
160-
->alias('session.storage.filesystem', 'session.storage.mock_file')
161-
->deprecate('symfony/framework-bundle', '5.3', 'The "%alias_id%" alias is deprecated, use "session.storage.factory.mock_file" instead.')
162-
16393
->set('session.marshaller', IdentityMarshaller::class)
16494

16595
->set('session.marshalling_handler', MarshallingSessionHandler::class)

0 commit comments

Comments
 (0)
0