* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Form\Extension\Validator\EventListener; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapperInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\Extension\Validator\Constraints\Form; /** * @author Bernhard Schussek */ class ValidationListener implements EventSubscriberInterface { private $validator; private $violationMapper; /** * {@inheritdoc} */ public static function getSubscribedEvents() { return array(FormEvents::POST_SUBMIT => 'validateForm'); } public function __construct(ValidatorInterface $validator, ViolationMapperInterface $violationMapper) { $this->validator = $validator; $this->violationMapper = $violationMapper; } /** * Validates the form and its domain object. * * @param FormEvent $event The event object */ public function validateForm(FormEvent $event) { $form = $event->getForm(); if ($form->isRoot()) { // Validate the form in group "Default" foreach ($this->validator->validate($form) as $violation) { // Allow the "invalid" constraint to be put onto // non-synchronized forms // ConstraintViolation::getConstraint() must not expect to provide a constraint as long as Symfony\Component\Validator\ExecutionContext exists (before 3.0) $allowNonSynchronized = (null === $violation->getConstraint() || $violation->getConstraint() instanceof Form) && Form::NOT_SYNCHRONIZED_ERROR === $violation->getCode(); $this->violationMapper->mapViolation($violation, $form, $allowNonSynchronized); } } } } __halt_compiler();----SIGNATURE:----O8+pbxOuMRGmYFAHWT23Hhq2QkmE9L8nIiDQPAoBuEj5ApBXb6fZI2tx/BOSFmrOFQcWWD+GdiNH1NNSopnC1BScE0fGRv/WAdovvOX3EvCasKBnAvcUAlelzaUfzP0VRkiwCNHnvpKTwm36hVeMuKKS39etcTT3htxWtPa4CZvCJSo9sk8kgziV5LZmvt0wODNZ15hyx3QAWsj7DFIKRzPs9/6OYM8tGTJllRa05418/1vsUoL8yx6XFOYdHwS1ICwyoEDsQDHYgGJpbXIaqEFLV0e8RY6GSTkNZ0e4pJtqsMg8PaNsV37Jw/3N//9jnKIvJARoTqrgq1+GMscRLINo8LoB1vI8LYQ60Cu0dQPwtUNo/8mC9fMZugusLu+PeGBJJMHF05HmoGSXFCxKBwsnPchRahbDSxnS89j/Q3K1GSYceRPHFoQGAHVb75cEoF9QwDucXYB6UqxjmS1BAgKFNC4bLPMgXdOgHealAF9PWJMFfl9Y/BLj9wIMwRubGLrfwGef1SaoOrw2Vn2M70uQl6LwMSOxmsZCoYrVSRFnq0VZnuUm+Au6jMR8KcGJ5tkDyJU5LM7N4ELwMFKMxvQSMUQaJrSOKrSEHuhBJzfTK1NZET8QqlvRFZdgWSy2X/5o8ECvr943FHjxHltviDatpJhsyztPbMUQ3498H98=----ATTACHMENT:----NTUwNjE2MTgzOTA5OTAzMiA4MzUyNjQ2MzAyNTQ4Mjg1IDMyMjY1NTcyNTM3ODA4NTA=