@@ -46,12 +46,34 @@ looks like this::
46
46
// ...
47
47
}
48
48
49
- By calling ``validate `` on the validator, you can pass in a raw value and
49
+ By calling ``validate() `` on the validator, you can pass in a raw value and
50
50
the constraint object that you want to validate that value against. A full
51
51
list of the available constraints - as well as the full class name for each
52
52
constraint - is available in the :doc: `constraints reference </reference/constraints >`
53
53
section.
54
54
55
+ Validation of arrays is possible using the ``Collection `` constraint::
56
+
57
+ use Symfony\Component\Validator\Validation;
58
+ use Symfony\Component\Validator\Constraints as Assert;
59
+
60
+ $validator = Validation::createValidator();
61
+
62
+ $constraint = new Assert\Collection(array(
63
+ // the keys correspond to the keys in the input array
64
+ 'name' => new Assert\Collection(array(
65
+ 'first_name' => new Assert\Length(array('min' => 101)),
66
+ 'last_name' => new Assert\Length(array('min' => 1)),
67
+ )),
68
+ 'email' => new Assert\Email(),
69
+ 'simple' => new Assert\Length(array('min' => 102)),
70
+ 'gender' => new Assert\Choice(array(3, 4)),
71
+ 'file' => new Assert\File(),
72
+ 'password' => new Assert\Length(array('min' => 60)),
73
+ ));
74
+
75
+ $violations = $validator->validateValue($input, $constraint);
76
+
55
77
The ``validate() `` method returns a :class: `Symfony\\ Component\\ Validator\\ ConstraintViolationList `
56
78
object, which acts just like an array of errors. Each error in the collection
57
79
is a :class: `Symfony\\ Component\\ Validator\\ ConstraintViolation ` object,
0 commit comments