Skip to content

Commit f5310ce

Browse files
committed
minor #37217 [FrameworkBundle] Move session configuration to PHP (cocorambo)
This PR was squashed before being merged into the 5.2-dev branch. Discussion ---------- [FrameworkBundle] Move session configuration to PHP | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Fix #37186 | License | MIT Move session configuration file to php Commits ------- de8f07d [FrameworkBundle] Move session configuration to PHP
2 parents d5aa77e + de8f07d commit f5310ce

File tree

3 files changed

+120
-98
lines changed

3 files changed

+120
-98
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public function load(array $configs, ContainerBuilder $container)
275275
}
276276

277277
$this->sessionConfigEnabled = true;
278-
$this->registerSessionConfiguration($config['session'], $container, $loader);
278+
$this->registerSessionConfiguration($config['session'], $container, $phpLoader);
279279
if (!empty($config['test'])) {
280280
$container->getDefinition('test.session.listener')->setArgument(1, '%session.storage.options%');
281281
}
@@ -932,9 +932,9 @@ private function registerRouterConfiguration(array $config, ContainerBuilder $co
932932
}
933933
}
934934

935-
private function registerSessionConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
935+
private function registerSessionConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader)
936936
{
937-
$loader->load('session.xml');
937+
$loader->load('session.php');
938938

939939
// session storage
940940
$container->setAlias('session.storage', $config['storage_id'])->setPrivate(true);
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
15+
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
16+
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
17+
use Symfony\Component\HttpFoundation\Session\Session;
18+
use Symfony\Component\HttpFoundation\Session\SessionInterface;
19+
use Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler;
20+
use Symfony\Component\HttpFoundation\Session\Storage\Handler\IdentityMarshaller;
21+
use Symfony\Component\HttpFoundation\Session\Storage\Handler\MarshallingSessionHandler;
22+
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler;
23+
use Symfony\Component\HttpFoundation\Session\Storage\Handler\SessionHandlerFactory;
24+
use Symfony\Component\HttpFoundation\Session\Storage\Handler\StrictSessionHandler;
25+
use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
26+
use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage;
27+
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
28+
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage;
29+
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
30+
use Symfony\Component\HttpKernel\EventListener\SessionListener;
31+
32+
return static function (ContainerConfigurator $container) {
33+
$container->parameters()->set('session.metadata.storage_key', '_sf2_meta');
34+
35+
$container->services()
36+
->set('session', Session::class)
37+
->public()
38+
->args([
39+
service('session.storage'),
40+
null, // AttributeBagInterface
41+
null, // FlashBagInterface
42+
[service('session_listener'), 'onSessionUsage'],
43+
])
44+
->alias(SessionInterface::class, 'session')
45+
->alias(SessionStorageInterface::class, 'session.storage')
46+
->alias(\SessionHandlerInterface::class, 'session.handler')
47+
48+
->set('session.storage.metadata_bag', MetadataBag::class)
49+
->args([
50+
param('session.metadata.storage_key'),
51+
param('session.metadata.update_threshold'),
52+
])
53+
54+
->set('session.storage.native', NativeSessionStorage::class)
55+
->args([
56+
param('session.storage.options'),
57+
service('session.handler'),
58+
service('session.storage.metadata_bag'),
59+
])
60+
61+
->set('session.storage.php_bridge', PhpBridgeSessionStorage::class)
62+
->args([
63+
service('session.handler'),
64+
service('session.storage.metadata_bag'),
65+
])
66+
67+
->set('session.flash_bag', FlashBag::class)
68+
->factory([service('session'), 'getFlashBag'])
69+
->deprecate('symfony/framework-bundle', '5.1', 'The "%service_id%" service is deprecated, use "$session->getFlashBag()" instead.')
70+
->alias(FlashBagInterface::class, 'session.flash_bag')
71+
72+
->set('session.attribute_bag', AttributeBag::class)
73+
->factory([service('session'), 'getBag'])
74+
->args(['attributes'])
75+
->deprecate('symfony/framework-bundle', '5.1', 'The "%service_id%" service is deprecated, use "$session->getAttributeBag()" instead.')
76+
77+
->set('session.storage.mock_file', MockFileSessionStorage::class)
78+
->args([
79+
param('kernel.cache_dir').'/sessions',
80+
'MOCKSESSID',
81+
service('session.storage.metadata_bag'),
82+
])
83+
84+
->set('session.handler.native_file', StrictSessionHandler::class)
85+
->args([
86+
inline_service(NativeFileSessionHandler::class)
87+
->args([param('session.save_path')]),
88+
])
89+
90+
->set('session.abstract_handler', AbstractSessionHandler::class)
91+
->factory([SessionHandlerFactory::class, 'createHandler'])
92+
->args([abstract_arg('A string or a connection object')])
93+
94+
->set('session_listener', SessionListener::class)
95+
->args([
96+
service_locator([
97+
'session' => service('session')->ignoreOnInvalid(),
98+
'initialized_session' => service('session')->ignoreOnUninitialized(),
99+
'logger' => service('logger')->ignoreOnInvalid(),
100+
]),
101+
param('kernel.debug'),
102+
])
103+
->tag('kernel.event_subscriber')
104+
105+
// for BC
106+
->alias('session.storage.filesystem', 'session.storage.mock_file')
107+
108+
->set('session.marshaller', IdentityMarshaller::class)
109+
110+
->set('session.marshalling_handler', MarshallingSessionHandler::class)
111+
->decorate('session.handler')
112+
->args([
113+
service('session.marshalling_handler.inner'),
114+
service('session.marshaller'),
115+
])
116+
;
117+
};

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

Lines changed: 0 additions & 95 deletions
This file was deleted.

0 commit comments

Comments
 (0)