* * 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:----JWVI+LdoluK7g06schm1MYt05/wqmHmwBpUyQxfEZPdvuoVC7N6rX6nrOIdhF0CuGmYWQi6UQaMJLUelUNN91h3gWoneuuaYKs+Tj3CX7gHOSDEJ7E6WmuQKt10AkHJGImiLaKI5Glug1GIP52bQHxmvNU4BQvTmMDEMitoDFLPo1YnFdjeDrSgtUWX9wZAW8ZB86gcxyKAoBfNj9oPQjFMN2mSWZQjC/njCjzBcjF/iALhiH33E2tIBGzSbN0TuWWQZNSh1j8KxTDH2LwzsDMfDLuY1gWwxOtGQ/UfF40A8HWdbgTCfmH1p5mzkcvxghSER/Kiq06VjWaBnVyATQS3qvXIVnbkgf1ANfR3luL/hekTk8WA0dQuvM6j2wWnAmCKs4m8vjpT5EVtiYrHnv+CnDZ+FgonkRtpKQWHNspreJ/53aJjqNB0TRyQYnBnTXDekgXOa1NmEUnhRJ4aZ5gvW7l6S8qZAieA6TJgO4sSJy7pjw0LqAO0xkUqC9nS1WA/9sEvqNAwOPcyK9d+BLb6P/aW1fZRofufpfgkFTCyURIOry/OfZi+R11kYG9vgHpg9GONHkn7vL/+BWoo91A/xS+jL+LQcKIf2KJcD3fj1S19psyAHP4mfh8Pwr3BzzqTkCBapx9eFRyL1HfTIaGFTvRsYQmMyuhbaWM3ulxk=----ATTACHMENT:----Nzc5NDMwMzU5OTk1ODM0MyA1MTU1MzU4MzAwNzczNjMgNDU4ODcxODAxODU1MTc0Ng==