29b6f6b3a0
* 2.3: made {@inheritdoc} annotations consistent across the board fixed types in phpdocs made phpdoc types consistent with those defined in Hack Add support Thai translations made types consistent with those defined in Hack removed extra/unsupported arguments [HttpKernel] fixed an error message [TwigBundle] removed undefined argument [Translation] Make IcuDatFileLoader/IcuResFileLoader::load invalid resource compatible with HHVM. Conflicts: src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service.php src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php src/Symfony/Bundle/FrameworkBundle/Templating/Loader/FilesystemLoader.php src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php src/Symfony/Component/Config/Definition/ReferenceDumper.php src/Symfony/Component/Console/Helper/DescriptorHelper.php src/Symfony/Component/Debug/ErrorHandler.php src/Symfony/Component/Finder/Tests/Iterator/RecursiveDirectoryIteratorTest.php src/Symfony/Component/Form/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformer.php src/Symfony/Component/Form/Tests/Extension/Core/DataMapper/PropertyPathMapperTest.php src/Symfony/Component/HttpFoundation/Response.php src/Symfony/Component/HttpFoundation/StreamedResponse.php src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php src/Symfony/Component/HttpKernel/Fragment/FragmentHandler.php src/Symfony/Component/HttpKernel/Fragment/RoutableFragmentRenderer.php src/Symfony/Component/HttpKernel/Kernel.php src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php src/Symfony/Component/Stopwatch/StopwatchPeriod.php src/Symfony/Component/Translation/TranslatorInterface.php src/Symfony/Component/Validator/ConstraintValidatorFactory.php
73 lines
2.2 KiB
PHP
73 lines
2.2 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Symfony package.
|
|
*
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Symfony\Component\Form\Extension\Csrf;
|
|
|
|
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
|
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
|
|
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
|
|
use Symfony\Component\Form\AbstractExtension;
|
|
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
|
use Symfony\Component\Translation\TranslatorInterface;
|
|
|
|
/**
|
|
* This extension protects forms by using a CSRF token.
|
|
*
|
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
|
*/
|
|
class CsrfExtension extends AbstractExtension
|
|
{
|
|
/**
|
|
* @var CsrfTokenManagerInterface
|
|
*/
|
|
private $tokenManager;
|
|
|
|
/**
|
|
* @var TranslatorInterface
|
|
*/
|
|
private $translator;
|
|
|
|
/**
|
|
* @var null|string
|
|
*/
|
|
private $translationDomain;
|
|
|
|
/**
|
|
* Constructor.
|
|
*
|
|
* @param CsrfTokenManagerInterface $tokenManager The CSRF token manager
|
|
* @param TranslatorInterface $translator The translator for translating error messages
|
|
* @param null|string $translationDomain The translation domain for translating
|
|
*/
|
|
public function __construct($tokenManager, TranslatorInterface $translator = null, $translationDomain = null)
|
|
{
|
|
if ($tokenManager instanceof CsrfProviderInterface) {
|
|
$tokenManager = new CsrfProviderAdapter($tokenManager);
|
|
} elseif (!$tokenManager instanceof CsrfTokenManagerInterface) {
|
|
throw new UnexpectedTypeException($tokenManager, 'CsrfProviderInterface or CsrfTokenManagerInterface');
|
|
}
|
|
|
|
$this->tokenManager = $tokenManager;
|
|
$this->translator = $translator;
|
|
$this->translationDomain = $translationDomain;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function loadTypeExtensions()
|
|
{
|
|
return array(
|
|
new Type\FormTypeCsrfExtension($this->tokenManager, true, '_token', $this->translator, $this->translationDomain),
|
|
);
|
|
}
|
|
}
|