8000 feature #41321 [FrameworkBundle] Remove deprecate session service (jd… · symfony/symfony@062ac36 · GitHub
[go: up one dir, main page]

Skip to content

Commit 062ac36

Browse files
feature #41321 [FrameworkBundle] Remove deprecate session service (jderusse)
This PR was merged into the 6.0 branch. Discussion ---------- [FrameworkBundle] Remove deprecate session service | Q | A | ------------- | --- | Branch? | 6.0 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - To ease code review this PR only removes code for session. Blocked by #41343 Commits ------- 9e6a3d3 Remove deprecate session service
2 parents 07dfb3e + 9e6a3d3 commit 062ac36

38 files changed

+116
-766
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;
@@ -93,7 +92,6 @@ public static function getSubscribedServices(): array
9392
'request_stack' => '?'.RequestStack::class,
9493
'http_kernel' => '?'.HttpKernelInterface::class,
9594
'serializer' => '?'.SerializerInterface::class,
96-
'session' => '?'.SessionInterface::class,
9795
'security.authorization_checker' => '?'.AuthorizationCheckerInterface::class,
9896
'twig' => '?'.Environment::class,
9997
'doctrine' => '?'.ManagerRegistry::class, // to be removed in 6.0

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
@@ -610,15 +610,8 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
610610
->arrayNode('session')
611611
->info('session configuration')
612612
->canBeEnabled()
613-
->beforeNormalization()
614-
->ifTrue(function ($v) {
615-
return \is_array($v) && isset($v['storage_id']) && isset($v['storage_factory_id']);
616-
})
617-
->thenInvalid('You cannot use both "storage_id" and "storage_factory_id" at the same time under "framework.session"')
618-
->end()
619613
->children()
620-
->scalarNode('storage_id')->defaultValue('session.storage.native')->end()
621-
->scalarNode('storage_factory_id')->defaultNull()->end()
614+
->scalarNode('storage_factory_id')->defaultValue('session.storage.factory.native')->end()
622615
->scalarNode('handler_id')->defaultValue('session.handler.native_file')->end()
623616
->scalarNode('name')
624617
->validate()

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

+5-32
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
use Symfony\Component\HttpClient\RetryableHttpClient;
7474
use Symfony\Component\HttpClient\ScopingHttpClient;
7575
use Symfony\Component\HttpFoundation\Request;
76-
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
7776
use Symfony\Component\HttpKernel\Attribute\AsController;
7877
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
7978
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
@@ -1057,20 +1056,7 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
10571056
$loader->load('session.php');
10581057

10591058
// session storage
1060-
if (null === $config['storage_factory_id']) {
1061-
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.');
1062-
$container->setAlias('session.storage', $config['storage_id']);
1063-
$container->setAlias('session.storage.factory', 'session.storage.factory.service');
1064-
} else {
1065-
$container->setAlias('session.storage.factory', $config['storage_factory_id']);
1066-
1067-
$container->removeAlias(SessionStorageInterface::class);
1068-
$container->removeDefinition('session.storage.metadata_bag');
1069-
$container->removeDefinition('session.storage.native');
1070-
$container->removeDefinition('session.storage.php_bridge');
1071-
$container->removeDefinition('session.storage.mock_file');
1072-
$container->removeAlias('session.storage.filesystem');
1073-
}
1059+
$container->setAlias('session.storage.factory', $config['storage_factory_id']);
10741060

10751061
$options = ['cache_limiter' => '0'];
10761062
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) {
@@ -1080,30 +1066,17 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
10801066
}
10811067

10821068
if ('auto' === ($options['cookie_secure'] ?? null)) {
1083-
if (null === $config['storage_factory_id']) {
1084-
$locator = $container->getDefinition('session_listener')->getArgument(0);
1085-
$locator->setValues($locator->getValues() + [
1086-
'session_storage' => new Reference('session.storage', ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
1087-
'request_stack' => new Reference('request_stack'),
1088-
]);
1089-
} else {
1090-
$container->getDefinition('session.storage.factory.native')->replaceArgument(3, true);
1091-
$container->getDefinition('session.storage.factory.php_bridge')->replaceArgument(2, true);
1092-
}
1069+
$container->getDefinition('session.storage.factory.native')->replaceArgument(3, true);
1070+
$container->getDefinition('session.storage.factory.php_bridge')->replaceArgument(2, true);
10931071
}
10941072

10951073
$container->setParameter('session.storage.options', $options);
10961074

10971075
// session handler (the internal callback registered with PHP session management)
10981076
if (null === $config['handler_id']) {
10991077
// Set the handler class to be null
1100-
if ($container->hasDefinition('session.storage.native')) {
1101-
$container->getDefinition('session.storage.native')->replaceArgument(1, null);
1102-
$container->getDefinition('session.storage.php_bridge')->replaceArgument(0, null);
1103-
} else {
1104-
$container->getDefinition('session.storage.factory.native')->replaceArgument(1, null);
1105-
$container->getDefinition('session.storage.factory.php_bridge')->replaceArgument(0, null);
1106-
}
1078+
$container->getDefinition('session.storage.factory.native')->replaceArgument(1, null);
1079+
$container->getDefinition('session.storage.factory.php_bridge')->replaceArgument(0, null);
11071080

11081081
$container->setAlias('session.handler', 'session.handler.native_file');
11091082
} 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/KernelBrowser.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ public function loginUser(object $user, string $firewallContext = 'main'): self
127127
$container = $this->getContainer();
128128
$container->get('security.untracked_token_storage')->setToken($token);
129129

130-
if (!$container->has('session') && !$container->has('session_factory')) {
130+
if (!$container->has('session.factory')) {
131131
return $this;
132132
}
133133

134-
$session = $container->get($container->has('session') ? 'session' : 'session_factory');
134+
$session = $container->get('session.factory')->createSession();
135135
$session->set('_security_'.$firewallContext, serialize($token));
136136
$session->save();
137137

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\Bundle\FrameworkBundle\Session\ServiceSessionFactory;
16-
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
17-
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
18-
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
19-
use Symfony\Component\HttpFoundation\Session\Session;
2014
use Symfony\Component\HttpFoundation\Session\SessionFactory;
21-
use Symfony\Component\HttpFoundation\Session\SessionInterface;
2215
use Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler;
2316
use Symfony\Component\HttpFoundation\Session\Storage\Handler\IdentityMarshaller;
2417
use Symfony\Component\HttpFoundation\Session\Storage\Handler\MarshallingSessionHandler;
2518
use Symfony\Component\Htt 325D pFoundation\Session\Storage\Handler\NativeFileSessionHandler;
2619
use Symfony\Component\HttpFoundation\Session\Storage\Handler\SessionHandlerFactory;
2720
use Symfony\Component\HttpFoundation\Session\Storage\Handler\StrictSessionHandler;
2821
use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
29-
use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage;
3022
use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorageFactory;
31-
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
3223
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorageFactory;
33-
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage;
3424
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorageFactory;
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,8 +83,6 @@
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
]),
@@ -158,10 +92,6 @@
15892
->tag('kernel.event_subscriber')
15993
->tag('kernel.reset', ['method' => 'reset'])
16094

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

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

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

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
->set('test.session.listener', SessionListener::class)
3939
->args([
4040
service_locator([
41-
'session' => service('.session.do-not-use')->ignoreOnInvalid(),
4241
'session_factory' => service('session.factory')->ignoreOnInvalid(),
4342
]),
4443
param('kernel.debug'),

0 commit comments

Comments
 (0)
0