4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Form\Extension\Csrf
;
14 use Symfony\Component\Form\Extension\Csrf\Type
;
15 use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface
;
16 use Symfony\Component\Form\AbstractExtension
;
17 use Symfony\Component\Translation\TranslatorInterface
;
20 * This extension protects forms by using a CSRF token.
22 * @author Bernhard Schussek <bschussek@gmail.com>
24 class CsrfExtension
extends AbstractExtension
27 * @var CsrfProviderInterface
29 private $csrfProvider;
32 * @var TranslatorInterface
39 private $translationDomain;
44 * @param CsrfProviderInterface $csrfProvider The CSRF provider
45 * @param TranslatorInterface $translator The translator for translating error messages.
46 * @param null|string $translationDomain The translation domain for translating.
48 public function __construct(CsrfProviderInterface
$csrfProvider, TranslatorInterface
$translator = null, $translationDomain = null)
50 $this->csrfProvider
= $csrfProvider;
51 $this->translator
= $translator;
52 $this->translationDomain
= $translationDomain;
58 protected function loadTypeExtensions()
61 new Type\
FormTypeCsrfExtension($this->csrfProvider
, true, '_token', $this->translator
, $this->translationDomain
),