* * 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\EventListener; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormError; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\Util\ServerParams; use Symfony\Component\Security\Csrf\CsrfToken; use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; use Symfony\Component\Translation\TranslatorInterface; /** * @author Bernhard Schussek */ class CsrfValidationListener implements EventSubscriberInterface { private $fieldName; private $tokenManager; private $tokenId; private $errorMessage; private $translator; private $translationDomain; private $serverParams; public static function getSubscribedEvents() { return array( FormEvents::PRE_SUBMIT => 'preSubmit', ); } public function __construct($fieldName, CsrfTokenManagerInterface $tokenManager, $tokenId, $errorMessage, TranslatorInterface $translator = null, $translationDomain = null, ServerParams $serverParams = null) { $this->fieldName = $fieldName; $this->tokenManager = $tokenManager; $this->tokenId = $tokenId; $this->errorMessage = $errorMessage; $this->translator = $translator; $this->translationDomain = $translationDomain; $this->serverParams = $serverParams ?: new ServerParams(); } public function preSubmit(FormEvent $event) { $form = $event->getForm(); $postRequestSizeExceeded = 'POST' === $form->getConfig()->getMethod() && $this->serverParams->hasPostMaxSizeBeenExceeded(); if ($form->isRoot() && $form->getConfig()->getOption('compound') && !$postRequestSizeExceeded) { $data = $event->getData(); if (!isset($data[$this->fieldName]) || !$this->tokenManager->isTokenValid(new CsrfToken($this->tokenId, $data[$this->fieldName]))) { $errorMessage = $this->errorMessage; if (null !== $this->translator) { $errorMessage = $this->translator->trans($errorMessage, array(), $this->translationDomain); } $form->addError(new FormError($errorMessage)); } if (is_array($data)) { unset($data[$this->fieldName]); $event->setData($data); } } } } __halt_compiler();----SIGNATURE:----BokUiDV13WKwJt6NtmxZq7BDbZazuw7lm/hlwsNqJ4ASkqTJA4UjljrTgGbPptt2k2egW3Ojn9v3rOSf1fm10vEH0a1ZbfyyWitsceH1qpA+RqxNruLkb4/ICQTKMSoZIGoJ1kqbDcpdtl0R5gjHn5G6VEUnM+IOxWScAnLS8a7IEoiEcv4C7QOfZQnAJjChVikhBuJ/xRexoaty9bgZB1zsFjRUkyVbHmVfgxTu/J4PgT+COLxMROpju9GbTcRDnHua2HyU9yMNScazLWZ1yn9t4AhnVWkZy3rWZE5PytHzI2T6wkINm1jpynxU6DL+dU4bmo/gDzlUNrADpN/hqPoPcdKYW3T3Z/NW08W71yRBLaTCAV9HKqWDIwCIpvqnGgcRorvvReUyef21CDsv5GAmtrnC/Hf+S9DT4fWh2AODeCCqGPLKi1jDVErfCHaD7CWNdl6zn+CUaXtzN0VjbytKcVAZRU6b/0J+vJqqWePdmNtiKMflsEpYVRN1XFMW/503n6xjNPu+MYdOx06LMaH1mwlCYGy4xAcuAHdst9l8W7rWsWSC532aY0LKfFdxmVOHwiT1etEgC0wFOmydPGjj9P3K0A/agpEYwY4l/dbuxRkU7HvcQ5uMbIMsa6IzGKyvrYMHT78UPhC+dqQu91bEdw7Kyn9ayXIE6TlE1Zs=----ATTACHMENT:----NzYzODExMzE4ODE2MzgzNCA3MzM0NTU4Njk3OTI5MzI4IDY3OTg5MzU4MTc3NTE1NTk=