diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index c1e838f79b9c8..50d0e768da839 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -275,7 +275,7 @@ public function load(array $configs, ContainerBuilder $container) } $this->sessionConfigEnabled = true; - $this->registerSessionConfiguration($config['session'], $container, $loader); + $this->registerSessionConfiguration($config['session'], $container, $phpLoader); if (!empty($config['test'])) { $container->getDefinition('test.session.listener')->setArgument(1, '%session.storage.options%'); } @@ -932,9 +932,9 @@ private function registerRouterConfiguration(array $config, ContainerBuilder $co } } - private function registerSessionConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader) + private function registerSessionConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader) { - $loader->load('session.xml'); + $loader->load('session.php'); // session storage $container->setAlias('session.storage', $config['storage_id'])->setPrivate(true); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.php new file mode 100644 index 0000000000000..0f5e5de071009 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.php @@ -0,0 +1,117 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\DependencyInjection\Loader\Configurator; + +use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; +use Symfony\Component\HttpFoundation\Session\Flash\FlashBag; +use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\SessionInterface; +use Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler; +use Symfony\Component\HttpFoundation\Session\Storage\Handler\IdentityMarshaller; +use Symfony\Component\HttpFoundation\Session\Storage\Handler\MarshallingSessionHandler; +use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler; +use Symfony\Component\HttpFoundation\Session\Storage\Handler\SessionHandlerFactory; +use Symfony\Component\HttpFoundation\Session\Storage\Handler\StrictSessionHandler; +use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag; +use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage; +use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; +use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage; +use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface; +use Symfony\Component\HttpKernel\EventListener\SessionListener; + +return static function (ContainerConfigurator $container) { + $container->parameters()->set('session.metadata.storage_key', '_sf2_meta'); + + $container->services() + ->set('session', Session::class) + ->public() + ->args([ + service('session.storage'), + null, // AttributeBagInterface + null, // FlashBagInterface + [service('session_listener'), 'onSessionUsage'], + ]) + ->alias(SessionInterface::class, 'session') + ->alias(SessionStorageInterface::class, 'session.storage') + ->alias(\SessionHandlerInterface::class, 'session.handler') + + ->set('session.storage.metadata_bag', MetadataBag::class) + ->args([ + param('session.metadata.storage_key'), + param('session.metadata.update_threshold'), + ]) + + ->set('session.storage.native', NativeSessionStorage::class) + ->args([ + param('session.storage.options'), + service('session.handler'), + service('session.storage.metadata_bag'), + ]) + + ->set('session.storage.php_bridge', PhpBridgeSessionStorage::class) + ->args([ + service('session.handler'), + service('session.storage.metadata_bag'), + ]) + + ->set('session.flash_bag', FlashBag::class) + ->factory([service('session'), 'getFlashBag']) + ->deprecate('symfony/framework-bundle', '5.1', 'The "%service_id%" service is deprecated, use "$session->getFlashBag()" instead.') + ->alias(FlashBagInterface::class, 'session.flash_bag') + + ->set('session.attribute_bag', AttributeBag::class) + ->factory([service('session'), 'getBag']) + ->args(['attributes']) + ->deprecate('symfony/framework-bundle', '5.1', 'The "%service_id%" service is deprecated, use "$session->getAttributeBag()" instead.') + + ->set('session.storage.mock_file', MockFileSessionStorage::class) + ->args([ + param('kernel.cache_dir').'/sessions', + 'MOCKSESSID', + service('session.storage.metadata_bag'), + ]) + + ->set('session.handler.native_file', StrictSessionHandler::class) + ->args([ + inline_service(NativeFileSessionHandler::class) + ->args([param('session.save_path')]), + ]) + + ->set('session.abstract_handler', AbstractSessionHandler::class) + ->factory([SessionHandlerFactory::class, 'createHandler']) + ->args([abstract_arg('A string or a connection object')]) + + ->set('session_listener', SessionListener::class) + ->args([ + service_locator([ + 'session' => service('session')->ignoreOnInvalid(), + 'initialized_session' => service('session')->ignoreOnUninitialized(), + 'logger' => service('logger')->ignoreOnInvalid(), + ]), + param('kernel.debug'), + ]) + ->tag('kernel.event_subscriber') + + // for BC + ->alias('session.storage.filesystem', 'session.storage.mock_file') + + ->set('session.marshaller', IdentityMarshaller::class) + + ->set('session.marshalling_handler', MarshallingSessionHandler::class) + ->decorate('session.handler') + ->args([ + service('session.marshalling_handler.inner'), + service('session.marshaller'), + ]) + ; +}; diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml deleted file mode 100644 index eba617daa46bb..0000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - _sf2_meta - - - - - - - - null - null - - - onSessionUsage - - - - - - - - - %session.metadata.storage_key% - %session.metadata.update_threshold% - - - - %session.storage.options% - - - - - - - - - - - - The "%service_id%" service is deprecated, use "$session->getFlashBag()" instead. - - - - - - attributes - The "%service_id%" service is deprecated, use "$session->getAttributeBag()" instead. - - - - %kernel.cache_dir%/sessions - MOCKSESSID - - - - - - - %session.save_path% - - - - - - - - - - - - - - - - - %kernel.debug% - - - - - - - - - - - - -