Skip to content

Commit 8e8fa6b

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

File tree

54 files changed

+450
-39
lines changed

Some content is hidden

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

54 files changed

+450
-39
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: 33 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;
@@ -1012,7 +1013,20 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
10121013
$loader->load('session.php');
10131014

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

10231037
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-
]);
1038+
if (null === $config['storage_factory_id']) {
1039+
$locator = $container->getDefinition('session_listener')->getArgument(0);
1040+
$locator->setValues($locator->getValues() + [
1041+
'session_storage' => new Reference('session.storage', ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
1042+
'request_stack' => new Reference('request_stack'),
1043+
]);
1044+
} else {
1045+
$container->getDefinition('session.storage.factory.native')->replaceArgument(3, true);
1046+
$container->getDefinition('session.storage.factory.php_bridge')->replaceArgument(2, true);
1047+
}
10291048
}
10301049

10311050
$container->setParameter('session.storage.options', $options);
10321051

10331052
// session handler (the internal callback registered with PHP session management)
10341053
if (null === $config['handler_id']) {
10351054
// 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);
1055+
if ($container->hasDefinition('session.storage.native')) {
1056+
$container->getDefinition('session.storage.native')->replaceArgument(1, null);
1057+
$container->getDefinition('session.storage.php_bridge')->replaceArgument(0, null);
1058+
} else {
1059+
$container->getDefinition('session.storage.factory.native')->replaceArgument(1, null);
1060+
$container->getDefinition('session.storage.factory.php_bridge')->replaceArgument(0, null);
1061+
}
1062+
10381063
$container->setAlias('session.handler', 'session.handler.native_file');
10391064
} else {
10401065
$container->resolveEnvPlaceholders($config['handler_id'], null, $usedEnvs);

src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Symfony\Component\DependencyInjection\ContainerInterface;
1919
use Symfony\Component\HttpFoundation\Request;
2020
use Symfony\Component\HttpFoundation\Response;
21-
use Symfony\Component\HttpFoundation\Session\Session;
2221
use Symfony\Component\HttpKernel\HttpKernelBrowser;
2322
use Symfony\Component\HttpKernel\KernelInterface;
2423
use Symfony\Component\HttpKernel\Profiler\Profile as HttpProfile;
@@ -123,7 +122,7 @@ public function loginUser($user, string $firewallContext = 'main'): self
123122

124123
$token = new TestBrowserToken($user->getRoles(), $user);
125124
$token->setAuthenticated(true);
126-
$session = new Session($this->getContainer()->get('test.service_container')->get('session.storage'));
125+
$session = $this->getContainer()->get('test.service_container')->get('session.factory')->createSession();
127126
$session->set('_security_'.$firewallContext, serialize($token));
128127
$session->save();
129128

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: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
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\SessionFactory;
1920
use Symfony\Component\HttpFoundation\Session\SessionInterface;
2021
use Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler;
2122
use Symfony\Component\HttpFoundation\Session\Storage\Handler\IdentityMarshaller;
@@ -25,8 +26,12 @@
2526
use Symfony\Component\HttpFoundation\Session\Storage\Handler\StrictSessionHandler;
2627
use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
2728
use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage;
29+
use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorageFactory;
2830
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
31+
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorageFactory;
2932
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage;
33+
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorageFactory;
34+
use Symfony\Component\HttpFoundation\Session\Storage\ServiceSessionFactory;
3035
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
3136
use Symfony\Component\HttpKernel\EventListener\SessionListener;
3237

@@ -35,37 +40,80 @@
3540

3641
$container->services()
3742
->set('.session.do-not-use', Session::class) // to be removed in 6.0
43+
->factory([service('session.factory'), 'createSession'])
44+
->set('session.factory', SessionFactory::class)
3845
->args([
39-
service('session.storage'),
40-
null, // AttributeBagInterface
41-
null, // FlashBagInterface
46+
service('request_stack'),
47+
service('session.storage.factory'),
4248
[service('session_listener'), 'onSessionUsage'],
4349
])
50+
51+
->set('session.storage.factory.native', NativeSessionStorageFactory::class)
52+
->args([
53+
param('session.storage.options'),
54+
service('session.handler'),
55+
inline_service(MetadataBag::class)
56+
->args([
57+
param('session.metadata.storage_key'),
58+
param('session.metadata.update_threshold'),
59+
]),
60+
false,
61+
])
62+
->set('session.storage.factory.php_bridge', PhpBridgeSessionStorageFactory::class)
63+
->args([
64+
service('session.handler'),
65+
inline_service(MetadataBag::class)
66+
->args([
67+
param('session.metadata.storage_key'),
68+
param('session.metadata.update_threshold'),
69+
]),
70+
false,
71+
])
72+
->set('session.storage.factory.mock_file', MockFileSessionStorageFactory::class)
73+
->args([
74+
param('kernel.cache_dir').'/sessions',
75+
'MOCKSESSID',
76+
inline_service(MetadataBag::class)
77+
->args([
78+
param('session.metadata.storage_key'),
79+
param('session.metadata.update_threshold'),
80+
]),
81+
])
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.')
87+
4488
->set('.session.deprecated', SessionInterface::class) // to be removed in 6.0
4589
->factory([inline_service(DeprecatedSessionFactory::class)->args([service('request_stack')]), 'getSession'])
4690
->alias(SessionInterface::class, '.session.do-not-use')
4791
->deprecate('symfony/framework-bundle', '5.3', 'The "%alias_id%" alias is deprecated, use "$requestStack->getSession()" instead.')
4892
->alias(SessionStorageInterface::class, 'session.storage')
93+
->deprecate('symfony/framework-bundle', '5.3', 'The "%alias_id%" alias is deprecated, use "session.storage.factory" instead.')
4994
->alias(\SessionHandlerInterface::class, 'session.handler')
5095

5196
->set('session.storage.metadata_bag', MetadataBag::class)
5297
->args([
5398
param('session.metadata.storage_key'),
5499
param('session.metadata.update_threshold'),
55100
])
101+
->deprecate('symfony/framework-bundle', '5.3', 'The "%service_id%" service is deprecated, create your own "session.storage.factory" instead.')
56102

57103
->set('session.storage.native', NativeSessionStorage::class)
58104
->args([
59105
param('session.storage.options'),
60106
service('session.handler'),
61107
service('session.storage.metadata_bag'),
62108
])
109+
->deprecate('symfony/framework-bundle', '5.3', 'The "%service_id%" service is deprecated, use "session.storage.factory.native" instead.')
63110

64111
->set('session.storage.php_bridge', PhpBridgeSessionStorage::class)
65112
->args([
66113
service('session.handler'),
67114
service('session.storage.metadata_bag'),
68115
])
116+
->deprecate('symfony/framework-bundle', '5.3', 'The "%service_id%" service is deprecated, use "session.storage.factory.php_bridge" instead.')
69117

70118
->set('session.flash_bag', FlashBag::class)
71119
->factory([service('.session.do-not-use'), 'getFlashBag'])
@@ -83,6 +131,7 @@
83131
'MOCKSESSID',
84132
service('session.storage.metadata_bag'),
85133
])
134+
->deprecate('symfony/framework-bundle', '5.3', 'The "%service_id%" service is deprecated, use "session.storage.factory.mock_file" instead.')
86135

87136
->set('session.handler.native_file', StrictSessionHandler::class)
88137
->args([
@@ -108,6 +157,7 @@
108157

109158
// for BC
110159
->alias('session.storage.filesystem', 'session.storage.mock_file')
160+
->deprecate('symfony/framework-bundle', '5.3', 'The "%alias_id%" alias is deprecated, use "session.storage.factory.mock_file" instead.')
111161

112162
->set('session.marshaller', IdentityMarshaller::class)
113163

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