CsrfExtension.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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\Form\Extension\Csrf;
  11. use Symfony\Component\Form\Extension\Csrf\Type;
  12. use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
  13. use Symfony\Component\Form\AbstractExtension;
  14. /**
  15. * This extension protects forms by using a CSRF token
  16. */
  17. class CsrfExtension extends AbstractExtension
  18. {
  19. private $csrfProvider;
  20. /**
  21. * Constructor.
  22. *
  23. * @param CsrfProviderInterface $csrfProvider The CSRF provider
  24. */
  25. public function __construct(CsrfProviderInterface $csrfProvider)
  26. {
  27. $this->csrfProvider = $csrfProvider;
  28. }
  29. /**
  30. * {@inheritDoc}
  31. */
  32. protected function loadTypes()
  33. {
  34. return array(
  35. new Type\CsrfType($this->csrfProvider),
  36. );
  37. }
  38. /**
  39. * {@inheritDoc}
  40. */
  41. protected function loadTypeExtensions()
  42. {
  43. return array(
  44. new Type\ChoiceTypeCsrfExtension(),
  45. new Type\DateTypeCsrfExtension(),
  46. new Type\FileTypeCsrfExtension(),
  47. new Type\FormTypeCsrfExtension(),
  48. new Type\RepeatedTypeCsrfExtension(),
  49. new Type\TimeTypeCsrfExtension(),
  50. );
  51. }
  52. }