Skip to content

Commit e6f0c16

Browse files
committed
Deprecate session.storage
1 parent 4537f85 commit e6f0c16

File tree

55 files changed

+456
-38
lines changed

Some content is hidden

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

55 files changed

+456
-38
lines changed

UPGRADE-5.3.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Form
3131
FrameworkBundle
3232
---------------
3333

34+
* Deprecate the `session.storage` alias and `session.storage.*` services, use the `session.storage.factory` alias and `session.storage.factory.*` services instead
35+
* Deprecate the `framework.session.storage_id` configuration option, use the `framework.session.storage_factory_id` configuration option instead
3436
* Deprecate the `session` service and the `SessionInterface` alias, use the `\Symfony\Component\HttpFoundation\Request::getSession()` or the new `\Symfony\Component\HttpFoundation\RequestStack::getSession()` methods instead
3537

3638
HttpFoundation

UPGRADE-6.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ Form
6969
FrameworkBundle
7070
---------------
7171

72+
* Remove the `session.storage` alias and `session.storage.*` services, use the `session.storage.factory` alias and `session.storage.factory.*` services instead
73+
* Remove `framework.session.storage_id` configuration option, use the `framework.session.storage_factory_id` configuration option instead
7274
* 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
7375
* `MicroKernelTrait::configureRoutes()` is now always called with a `RoutingConfigurator`
7476
* The "framework.router.utf8" configuration option defaults to `true`

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ CHANGELOG
44
5.3
55
---
66

7+
* Deprecate the `session.storage` alias and `session.storage.*` services, use the `session.storage.factory` alias and `session.storage.factory.*` services instead
8+
* Deprecate the `framework.session.storage_id` configuration option, use the `framework.session.storage_factory_id` configuration option instead
79
* Deprecate the `session` service and the `SessionInterface` alias, use the `Request::getSession()` or the new `RequestStack::getSession()` methods instead
810
* Added `AbstractController::renderForm()` to render a form and set the appropriate HTTP status code
911
* Added support for configuring PHP error level to log levels

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class SessionPass implements CompilerPassInterface
2222
{
2323
public function process(ContainerBuilder $container)
2424
{
25-
if (!$container->has('session.storage')) {
25+
if (!$container->has('session.factory')) {
2626
return;
2727
}
2828

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
600600
->canBeEnabled()
601601
->children()
602602
->scalarNode('storage_id')->defaultValue('session.storage.native')->end()
603+
->scalarNode('storage_factory_id')->defaultNull()->end()
603604
->scalarNode('handler_id')->defaultValue('session.handler.native_file')->end()
604605
->scalarNode('name')
605606
->validate()

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

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
use Symfony\Component\HttpClient\RetryableHttpClient;
7171
use Symfony\Component\HttpClient\ScopingHttpClient;
7272
use Symfony\Component\HttpFoundation\Request;
73+
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
7374
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
7475
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
7576
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
@@ -143,6 +144,7 @@
143144
use Symfony\Component\RateLimiter\LimiterInterface;
144145
use Symfony\Component\RateLimiter\RateLimiterFactory;
145146
use Symfony\Component\RateLimiter\Storage\CacheStorage;
147+
use Symfony\Component\RateLimiter\Storage\StorageInterface;
146148
use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
147149
use Symfony\Component\Routing\Loader\AnnotationFileLoader;
148150
use Symfony\Component\Security\Core\Security;
@@ -1012,7 +1014,21 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
10121014
$loader->load('session.php');
10131015

10141016
// session storage
1015-
$container->setAlias('session.storage', $config['storage_id']);
1017+
if (null === $config['storage_factory_id']) {
1018+
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.');
1019+
$container->setAlias('session.storage', $config['storage_id']);
1020+
$container->setAlias('session.storage.factory', 'session.storage.factory.service');
1021+
1022+
} else {
1023+
$container->setAlias('session.storage.factory', $config['storage_factory_id']);
1024+
1025+
$container->removeAlias(SessionStorageInterface::class);
1026+
$container->removeDefinition('session.storage.metadata_bag');
1027+
$container->removeDefinition('session.storage.native');
1028+
$container->removeDefinition('session.storage.php_bridge');
1029+
$container->removeAlias('session.storage.filesystem');
1030+
}
1031+
10161032
$options = ['cache_limiter' => '0'];
10171033
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) {
10181034
if (isset($config[$key])) {
@@ -1021,20 +1037,31 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
10211037
}
10221038

10231039
if ('auto' === ($options['cookie_secure'] ?? null)) {
1024-
$locator = $container->getDefinition('session_listener')->getArgument(0);
1025-
$locator->setValues($locator->getValues() + [
1026-
'session_storage' => new Reference('session.storage', ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
1027-
'request_stack' => new Reference('request_stack'),
1028-
]);
1040+
if (null === $config['storage_factory_id']) {
1041+
$locator = $container->getDefinition('session_listener')->getArgument(0);
1042+
$locator->setValues($locator->getValues() + [
1043+
'session_storage' => new Reference('session.storage', ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
1044+
'request_stack' => new Reference('request_stack'),
1045+
]);
1046+
} else {
1047+
$container->getDefinition('session.storage.factory.native')->replaceArgument(3, true);
1048+
$container->getDefinition('session.storage.factory.php_bridge')->replaceArgument(2, true);
1049+
}
10291050
}
10301051

10311052
$container->setParameter('session.storage.options', $options);
10321053

10331054
// session handler (the internal callback registered with PHP session management)
10341055
if (null === $config['handler_id']) {
10351056
// Set the handler class to be null
1036-
$container->getDefinition('session.storage.native')->replaceArgument(1, null);
1037-
$container->getDefinition('session.storage.php_bridge')->replaceArgument(0, null);
1057+
if ($container->hasDefinition('session.storage.native')) {
1058+
$container->getDefinition('session.storage.native')->replaceArgument(1, null);
1059+
$container->getDefinition('session.storage.php_bridge')->replaceArgument(0, null);
1060+
} else {
1061+
$container->getDefinition('session.storage.factory.native')->replaceArgument(1, null);
1062+
$container->getDefinition('session.storage.factory.php_bridge')->replaceArgument(0, null);
1063+
}
1064+
10381065
$container->setAlias('session.handler', 'session.handler.native_file');
10391066
} else {
10401067
$container->resolveEnvPlaceholders($config['handler_id'], null, $usedEnvs);

src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function loginUser($user, string $firewallContext = 'main'): self
123123

124124
$token = new TestBrowserToken($user->getRoles(), $user);
125125
$token->setAuthenticated(true);
126-
$session = new Session($this->getContainer()->get('test.service_container')->get('session.storage'));
126+
$session = $this->getContainer()->get('test.service_container')->get('session.factory')->createSession();
127127
$session->set('_security_'.$firewallContext, serialize($token));
128128
$session->save();
129129

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106

107107
<xsd:complexType name="session">
108108
<xsd:attribute name="enabled" type="xsd:boolean" />
109+
<xsd:attribute name="storage-factory-id" type="xsd:string" />
109110
<xsd:attribute name="storage-id" type="xsd:string" />
110111
<xsd:attribute name="handler-id" type="xsd:string" />
111112
<xsd:attribute name="name" type="xsd:string" />

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

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
1717
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
1818
use Symfony\Component\HttpFoundation\Session\Session;
19+
use Symfony\Component\HttpFoundation\Session\AbstractSessionFactory;
20+
use Symfony\Component\HttpFoundation\Session\SessionFactory;
1921
use Symfony\Component\HttpFoundation\Session\SessionInterface;
2022
use Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler;
2123
use Symfony\Component\HttpFoundation\Session\Storage\Handler\IdentityMarshaller;
@@ -25,7 +27,11 @@
2527
use Symfony\Component\HttpFoundation\Session\Storage\Handler\StrictSessionHandler;
2628
use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
2729
use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage;
30+
use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorageFactory;
2831
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
32+
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorageFactory;
33+
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorageFactory;
34+
use Symfony\Component\HttpFoundation\Session\Storage\ServiceSessionFactory;
2935
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage;
3036
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
3137
use Symfony\Component\HttpKernel\EventListener\SessionListener;
@@ -35,37 +41,80 @@
3541

3642
$container->services()
3743
->set('.session.do-not-use', Session::class) // to be removed in 6.0
44+
->factory([service('session.factory'), 'createSession'])
45+
->set('session.factory', SessionFactory::class)
3846
->args([
39-
service('session.storage'),
40-
null, // AttributeBagInterface
41-
null, // FlashBagInterface
47+
service('request_stack'),
48+
service('session.storage.factory'),
4249
[service('session_listener'), 'onSessionUsage'],
4350
])
51+
52+
->set('session.storage.factory.native', NativeSessionStorageFactory::class)
53+
->args([
54+
param('session.storage.options'),
55+
service('session.handler'),
56+
inline_service(MetadataBag::class)
57+
->args([
58+
param('session.metadata.storage_key'),
59+
param('session.metadata.update_threshold'),
60+
]),
61+
false,
62+
])
63+
->set('session.storage.factory.php_bridge', PhpBridgeSessionStorageFactory::class)
64+
->args([
65+
service('session.handler'),
66+
inline_service(MetadataBag::class)
67+
->args([
68+
param('session.metadata.storage_key'),
69+
param('session.metadata.update_threshold'),
70+
]),
71+
false,
72+
])
73+
->set('session.storage.factory.mock_file', MockFileSessionStorageFactory::class)
74+
->args([
75+
param('kernel.cache_dir').'/sessions',
76+
'MOCKSESSID',
77+
inline_service(MetadataBag::class)
78+
->args([
79+
param('session.metadata.storage_key'),
80+
param('session.metadata.update_threshold'),
81+
]),
82+
])
83+
->set('session.storage.factory.service', ServiceSessionFactory::class)
84+
->args([
85+
service('session.storage'),
86+
])
87+
->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.')
88+
4489
->set('.session.deprecated', SessionInterface::class) // to be removed in 6.0
4590
->factory([inline_service(DeprecatedSessionFactory::class)->args([service('request_stack')]), 'getSession'])
4691
->alias(SessionInterface::class, '.session.do-not-use')
4792
->deprecate('symfony/framework-bundle', '5.3', 'The "%alias_id%" alias is deprecated, use "$requestStack->getSession()" instead.')
4893
->alias(SessionStorageInterface::class, 'session.storage')
94+
->deprecate('symfony/framework-bundle', '5.3', 'The "%alias_id%" alias is deprecated, use "session.storage.factory" instead.')
4995
->alias(\SessionHandlerInterface::class, 'session.handler')
5096

5197
->set('session.storage.metadata_bag', MetadataBag::class)
5298
->args([
5399
param('session.metadata.storage_key'),
54100
param('session.metadata.update_threshold'),
55101
])
102+
->deprecate('symfony/framework-bundle', '5.3', 'The "%service_id%" service is deprecated, create your own "session.storage.factory" instead.')
56103

57104
->set('session.storage.native', NativeSessionStorage::class)
58105
->args([
59106
param('session.storage.options'),
60107
service('session.handler'),
61108
service('session.storage.metadata_bag'),
62109
])
110+
->deprecate('symfony/framework-bundle', '5.3', 'The "%service_id%" service is deprecated, use "session.storage.factory.native" instead.')
63111

64112
->set('session.storage.php_bridge', PhpBridgeSessionStorage::class)
65113
->args([
66114
service('session.handler'),
67115
service('session.storage.metadata_bag'),
68116
])
117+
->deprecate('symfony/framework-bundle', '5.3', 'The "%service_id%" service is deprecated, use "session.storage.factory.php_bridge" instead.')
69118

70119
->set('session.flash_bag', FlashBag::class)
71120
->factory([service('.session.do-not-use'), 'getFlashBag'])
@@ -83,6 +132,7 @@
83132
'MOCKSESSID',
84133
service('session.storage.metadata_bag'),
85134
])
135+
->deprecate('symfony/framework-bundle', '5.3', 'The "%service_id%" service is deprecated, use "session.storage.factory.mock_file" instead.')
86136

87137
->set('session.handler.native_file', StrictSessionHandler::class)
88138
->args([
@@ -108,6 +158,7 @@
108158

109159
// for BC
110160
->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.')
111162

112163
->set('session.marshaller', IdentityMarshaller::class)
113164

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/SessionPassTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testProcess()
2222
{
2323
$container = new ContainerBuilder();
2424
$container
25-
->register('session.storage'); // marker service
25+
->register('session.factory'); // marker service
2626
$container
2727
->register('.session.do-not-use');
2828

@@ -41,7 +41,7 @@ public function testProcessUserDefinedSession()
4141
];
4242
$container = new ContainerBuilder();
4343
$container
44-
->register('session.storage'); // marker service
44+
->register('session.factory'); // marker service
4545
$container
4646
->register('session')
4747
->setArguments($arguments);
@@ -70,7 +70,7 @@ public function testProcessUserDefinedAlias()
7070
];
7171
$container = new ContainerBuilder();
7272
$container
73-
->register('session.storage'); // marker service
73+
->register('session.factory'); // marker service
7474
$container
7575
->register('trueSession')
7676
->setArguments($arguments);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy