8000 missing constraint example from the old readme · symfony/symfony-docs@c8b6b45 · GitHub
[go: up one dir, main page]

Skip to content

Commit c8b6b45

Browse files
CoolGoosewouterj
authored andcommitted
missing constraint example from the old readme
1 parent 8292f92 commit c8b6b45

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

components/validator.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,31 @@ characters long::
4545
echo $violation->getMessage().'<br>';
4646
}
4747
}
48+
49+
Validation of arrays is possible using the `Collection` constraint::
50+
51+
52+
use Symfony\Component\Validator\Validation;
53+
use Symfony\Component\Validator\Constraints as Assert;
54+
55+
$validator = Validation::createValidator();
56+
57+
$constraint = new Assert\Collection(array(
58+
'name' => new Assert\Collection(array(
59+
'first_name' => new Assert\Length(array('min' => 101)),
60+
'last_name' => new Assert\Length(array('min' => 1)),
61+
)),
62+
'email' => new Assert\Email(),
63+
'simple' => new Assert\Length(array('min' => 102)),
64+
'gender' => new Assert\Choice(array(3, 4)),
65+
'file' => new Assert\File(),
66+
'password' => new Assert\Length(array('min' => 60)),
67+
));
68+
69+
$violations = $validator->validateValue($input, $constraint);
70+
71+
72+
Again, the validator returns the list of violations.
4873

4974
Retrieving a Validator Instance
5075
-------------------------------

0 commit comments

Comments
 (0)
0