|
| 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\DependencyInjection\Loader\Configurator\ContainerConfigurator; |
| 15 | +use Symfony\Component\Security\Csrf\TokenGenerator\UriSafeTokenGenerator; |
| 16 | +use Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface; |
| 17 | +use Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage; |
| 18 | +use Symfony\Component\Security\Csrf\TokenStorage\TokenStorageInterface; |
| 19 | +use Symfony\Component\Security\Csrf\CsrfTokenManager; |
| 20 | +use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; |
| 21 | +use Symfony\Bridge\Twig\Extension\CsrfRuntime; |
| 22 | +use Symfony\Bridge\Twig\Extension\CsrfExtension; |
| 23 | + |
| 24 | +return static function (ContainerConfigurator $container) { |
| 25 | + $container->services() |
| 26 | + ->set('security.csrf.token_generator', UriSafeTokenGenerator::class) |
| 27 | + |
| 28 | + ->alias(TokenGeneratorInterface::class, 'security.csrf.token_generator') |
| 29 | + |
| 30 | + ->set('security.csrf.token_storage', SessionTokenStorage::class) |
| 31 | + ->args([service('session')]) |
| 32 | + |
| 33 | + ->alias(TokenStorageInterface::class, 'security.csrf.token_storage') |
| 34 | + |
| 35 | + ->set('security.csrf.token_manager', CsrfTokenManager::class) |
| 36 | + ->public() |
| 37 | + ->args([ |
| 38 | + service('security.csrf.token_generator'), |
| 39 | + service('security.csrf.token_storage'), |
| 40 | + service('request_stack')->ignoreOnInvalid() |
| 41 | + ]) |
| 42 | + |
| 43 | + ->alias(CsrfTokenManagerInterface::class, 'security.csrf.token_manager') |
| 44 | + |
| 45 | + ->set('twig.runtime.security_csrf', CsrfRuntime::class) |
| 46 | + ->args([service('security.csrf.token_manager')]) |
| 47 | + ->tag('twig.runtime') |
| 48 | + |
| 49 | + ->set('twig.extension.security_csrf', CsrfExtension::class) |
| 50 | + ->tag('twig.extension') |
| 51 | + ; |
| 52 | +}; |
0 commit comments