|
| 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 | +}; |
0 commit comments