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\Validator
;
14 use Symfony\Component\Form\Extension\Validator\Type
;
15 use Symfony\Component\Form\Extension\Validator\Constraints\Form
;
16 use Symfony\Component\Form\AbstractExtension
;
17 use Symfony\Component\Validator\ValidatorInterface
;
18 use Symfony\Component\Validator\Constraints\Valid
;
21 * Extension supporting the Symfony2 Validator component in forms.
23 * @author Bernhard Schussek <bschussek@gmail.com>
25 class ValidatorExtension
extends AbstractExtension
29 public function __construct(ValidatorInterface
$validator)
31 $this->validator
= $validator;
33 // Register the form constraints in the validator programmatically.
34 // This functionality is required when using the Form component without
35 // the DIC, where the XML file is loaded automatically. Thus the following
36 // code must be kept synchronized with validation.xml
38 /** @var \Symfony\Component\Validator\Mapping\ClassMetadata $metadata */
39 $metadata = $this->validator
->getMetadataFactory()->getMetadataFor('Symfony\Component\Form\Form');
40 $metadata->addConstraint(new Form());
41 $metadata->addPropertyConstraint('children', new Valid());
44 public function loadTypeGuesser()
46 return new ValidatorTypeGuesser($this->validator
->getMetadataFactory());
49 protected function loadTypeExtensions()
52 new Type\
FormTypeValidatorExtension($this->validator
),
53 new Type\
RepeatedTypeValidatorExtension(),
54 new Type\
SubmitTypeValidatorExtension(),