@@ -51,6 +51,26 @@ Validation of arrays is possible using the ``Collection`` constraint::
5151
5252 $validator = Validation::createValidator();
5353
54+ $input = array(
55+ 'name' => array(
56+ 'first_name' => 'Fabien',
57+ 'last_name' => 'Potencier',
58+ ),
59+ 'email' => 'test@email.tld',
60+ 'simple' => 'hello',
61+ 'gender' => 3,
62+ 'file' => null,
63+ 'password' => 'test',
64+ 'tags' => array(
65+ array(
66+ 'slug' => 'symfony_doc',
67+ 'label' => 'symfony doc',
68+ ),
69+ ),
70+ );
71+
72+ $groups = new Assert\GroupSequence(array('Default', 'custom'));
73+
5474 $constraint = new Assert\Collection(array(
5575 // the keys correspond to the keys in the input array
5676 'name' => new Assert\Collection(array(
@@ -62,9 +82,25 @@ Validation of arrays is possible using the ``Collection`` constraint::
6282 'gender' => new Assert\Choice(array(3, 4)),
6383 'file' => new Assert\File(),
6484 'password' => new Assert\Length(array('min' => 60)),
85+ 'tags' => new Assert\Optional(array(
86+ new Assert\Type('array'),
87+ new Assert\Count(array('min' => 1)),
88+ new Assert\All(array(
89+ new Assert\Collection(array(
90+ 'slug' => array(
91+ new Assert\NotBlank(),
92+ new Assert\Type(array('type' => 'string'))
93+ ),
94+ 'label' => array(
95+ new Assert\NotBlank(),
96+ ),
97+ )),
98+ new CustomUniqueTagValidator(array('groups' => 'custom')),
99+ )),
100+ )),
65101 ));
66102
67- $violations = $validator->validate($input, $constraint);
103+ $violations = $validator->validate($input, $constraint, $groups );
68104
69105The ``validate() `` method returns a :class: `Symfony\\ Component\\ Validator\\ ConstraintViolationList `
70106object, which acts just like an array of errors. Each error in the collection
0 commit comments