security_csrf.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\DependencyInjection\Loader\Configurator;
  11. use Symfony\Bridge\Twig\Extension\CsrfExtension;
  12. use Symfony\Bridge\Twig\Extension\CsrfRuntime;
  13. use Symfony\Component\Security\Csrf\CsrfTokenManager;
  14. use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
  15. use Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface;
  16. use Symfony\Component\Security\Csrf\TokenGenerator\UriSafeTokenGenerator;
  17. use Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage;
  18. use Symfony\Component\Security\Csrf\TokenStorage\TokenStorageInterface;
  19. return static function (ContainerConfigurator $container) {
  20. $container->services()
  21. ->set('security.csrf.token_generator', UriSafeTokenGenerator::class)
  22. ->alias(TokenGeneratorInterface::class, 'security.csrf.token_generator')
  23. ->set('security.csrf.token_storage', SessionTokenStorage::class)
  24. ->args([service('session')])
  25. ->alias(TokenStorageInterface::class, 'security.csrf.token_storage')
  26. ->set('security.csrf.token_manager', CsrfTokenManager::class)
  27. ->public()
  28. ->args([
  29. service('security.csrf.token_generator'),
  30. service('security.csrf.token_storage'),
  31. service('request_stack')->ignoreOnInvalid(),
  32. ])
  33. ->tag('container.private', ['package' => 'symfony/framework-bundle', 'version' => '5.2'])
  34. ->alias(CsrfTokenManagerInterface::class, 'security.csrf.token_manager')
  35. ->set('twig.runtime.security_csrf', CsrfRuntime::class)
  36. ->args([service('security.csrf.token_manager')])
  37. ->tag('twig.runtime')
  38. ->set('twig.extension.security_csrf', CsrfExtension::class)
  39. ->tag('twig.extension')
  40. ;
  41. };