Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e8e50ef

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

File tree

54 files changed

+456
-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

+456
-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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,15 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
598598
->arrayNode('session')
599599
->info('session configuration')
600600
->canBeEnabled()
601+
->beforeNormalization()
602+
->ifTrue(function ($v) {
603+
return is_array($v) && isset($v['storage_id']) && isset($v['storage_factory_id']);
604+
})
605+
->thenInvalid('You cannot use both "storage_id" and "storage_factory_id" at the same time under "framework.session"')
606+
->end()
601607
->children()
602608
->scalarNode('storage_id')->defaultValue('session.storage.native')->end()
609+
->scalarNode('storage_factory_id')->defaultNull()->end()
603610
->scalarNode('handler_id')->defaultValue('session.handler.native_file')->end()
604611
->scalarNode('name')
605612
->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);

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ protected static function getBundleDefaultConfig()
462462
'session' => [
463463
'enabled' => false,
464464
'storage_id' => 'session.storage.native',
465+
'storage_factory_id' => null,
465466
'handler_id' => 'session.handler.native_file',
466467
'cookie_httponly' => true,
467468
'cookie_samesite' => null,

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/csrf.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'legacy_error_messages' => false,
77
],
88
'session' => [
9+
'storage_factory_id' => 'session.storage.factory.native',
910
'handler_id' => null,
1011
],
1112
]);

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
'utf8' => true,
2828
],
2929
'session' => [
30-
'storage_id' => 'session.storage.native',
30+
'storage_factory_id' => 'session.storage.factory.native',
3131
'handler_id' => 'session.handler.native_file',
3232
'name' => '_SYMFONY',
3333
'cookie_lifetime' => 86400,

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/session.php

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

33
$container->loadFromExtension('framework', [
44
'session' => [
5+
'storage_factory_id' => 'session.storage.factory.native',
56
'handler_id' => null,
67
],
78
]);

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/session_cookie_secure_auto.php

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

33
$container->loadFromExtension('framework', [
44
'session' => [
5+
'storage_factory_id' => 'session.storage.factory.native',
56
'handler_id' => null,
67
'cookie_secure' => 'auto',
78
],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
// To be removed in Symfony 6.0
4+
$container->loadFromExtension('framework', [
5+
'session' => [
6+
'handler_id' => null,
7+
'cookie_secure' => 'auto',
8+
],
9+
]);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
// To be removed in Symfony 6.0
4+
$container->loadFromExtension('framework', [
5+
'session' => [
6+
'handler_id' => null,
7+
],
8+
]);

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/csrf.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
<framework:config>
1010
<framework:csrf-protection />
1111
<framework:form legacy-error-messages="false" />
12-
<framework:session />
12+
<framework:session storage-factory-id="session.storage.factory.native" />
1313
</framework:config>
1414
</container>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/form_csrf_sets_field_name.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<framework:config>
1010
<framework:csrf-protection field-name="_custom" />
11-
<framework:session />
11+
<framework:session storage-factory-id="session.storage.factory.native" />
1212
<framework:form legacy-error-messages="false" />
1313
</framework:config>
1414
</container>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/form_csrf_under_form_sets_field_name.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
<framework:config>
1010
<framework:csrf-protection field-name="_custom_form" />
1111
<framework:form legacy-error-messages="false" />
12-
<framework:session />
12+
<framework:session storage-factory-id="session.storage.factory.native" />
1313
</framework:config>
1414
</container>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<framework:ssi enabled="true" />
1616
<framework:profiler only-exceptions="true" enabled="false" />
1717
<framework:router resource="%kernel.project_dir%/config/routing.xml" type="xml" utf8="true" />
18-
<framework:session gc-maxlifetime="90000" gc-probability="1" gc-divisor="108" storage-id="session.storage.native" handler-id="session.handler.native_file" name="_SYMFONY" cookie-lifetime="86400" cookie-path="/" cookie-domain="example.com" cookie-secure="true" cookie-httponly="false" use-cookies="true" save-path="/path/to/sessions" sid-length="22" sid-bits-per-character="4" />
18+
<framework:session gc-maxlifetime="90000" gc-probability="1" gc-divisor="108" storage-factory-id="session.storage.factory.native" handler-id="session.handler.native_file" name="_SYMFONY" cookie-lifetime="86400" cookie-path="/" cookie-domain="example.com" cookie-secure="true" cookie-httponly="false" use-cookies="true" save-path="/path/to/sessions" sid-length="22" sid-bits-per-character="4" />
1919
<framework:request>
2020
<framework:format name="csv">
2121
<framework:mime-type>text/csv</framework:mime-type>

0 commit comments

Comments
 (0)