diff options
Diffstat (limited to 'vendor/symfony/form/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php')
-rw-r--r-- | vendor/symfony/form/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php new file mode 100644 index 00000000..344bddad --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php | |||
@@ -0,0 +1,84 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Validator\Type; | ||
13 | |||
14 | use Symfony\Component\Form\FormBuilderInterface; | ||
15 | use Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapper; | ||
16 | use Symfony\Component\Form\Extension\Validator\EventListener\ValidationListener; | ||
17 | use Symfony\Component\Validator\ValidatorInterface; | ||
18 | use Symfony\Component\OptionsResolver\Options; | ||
19 | use Symfony\Component\OptionsResolver\OptionsResolverInterface; | ||
20 | |||
21 | /** | ||
22 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
23 | */ | ||
24 | class FormTypeValidatorExtension extends BaseValidatorExtension | ||
25 | { | ||
26 | /** | ||
27 | * @var ValidatorInterface | ||
28 | */ | ||
29 | private $validator; | ||
30 | |||
31 | /** | ||
32 | * @var ViolationMapper | ||
33 | */ | ||
34 | private $violationMapper; | ||
35 | |||
36 | public function __construct(ValidatorInterface $validator) | ||
37 | { | ||
38 | $this->validator = $validator; | ||
39 | $this->violationMapper = new ViolationMapper(); | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * {@inheritdoc} | ||
44 | */ | ||
45 | public function buildForm(FormBuilderInterface $builder, array $options) | ||
46 | { | ||
47 | $builder->addEventSubscriber(new ValidationListener($this->validator, $this->violationMapper)); | ||
48 | } | ||
49 | |||
50 | /** | ||
51 | * {@inheritdoc} | ||
52 | */ | ||
53 | public function setDefaultOptions(OptionsResolverInterface $resolver) | ||
54 | { | ||
55 | parent::setDefaultOptions($resolver); | ||
56 | |||
57 | // Constraint should always be converted to an array | ||
58 | $constraintsNormalizer = function (Options $options, $constraints) { | ||
59 | return is_object($constraints) ? array($constraints) : (array) $constraints; | ||
60 | }; | ||
61 | |||
62 | $resolver->setDefaults(array( | ||
63 | 'error_mapping' => array(), | ||
64 | 'constraints' => array(), | ||
65 | 'cascade_validation' => false, | ||
66 | 'invalid_message' => 'This value is not valid.', | ||
67 | 'invalid_message_parameters' => array(), | ||
68 | 'extra_fields_message' => 'This form should not contain extra fields.', | ||
69 | 'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.', | ||
70 | )); | ||
71 | |||
72 | $resolver->setNormalizers(array( | ||
73 | 'constraints' => $constraintsNormalizer, | ||
74 | )); | ||
75 | } | ||
76 | |||
77 | /** | ||
78 | * {@inheritdoc} | ||
79 | */ | ||
80 | public function getExtendedType() | ||
81 | { | ||
82 | return 'form'; | ||
83 | } | ||
84 | } | ||