Skip to content

Commit 06f67b4

Browse files
committed
Moved array validation to the Raw values sub-guide
1 parent 64f5ad9 commit 06f67b4

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

components/validator.rst

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,8 @@ characters long::
4545
echo $violation->getMessage().'<br>';
4646
}
4747
}
48-
49-
Validation of arrays is possible using the ``Collection`` constraint::
5048

51-
use Symfony\Component\Validator\Validation;
52-
use Symfony\Component\Validator\Constraints as Assert;
53-
54-
$validator = Validation::createValidator();
55-
56-
$constraint = new Assert\Collection(array(
57-
'name' => new Assert\Collection(array(
58-
'first_name' => new Assert\Length(array('min' => 101)),
59-
'last_name' => new Assert\Length(array('min' => 1)),
60-
)),
61-
'email' => new Assert\Email(),
62-
'simple' => new Assert\Length(array('min' => 102)),
63-
'gender' => new Assert\Choice(array(3, 4)),
64-
'file' => new Assert\File(),
65-
'password' => new Assert\Length(array('min' => 60)),
66-
));
67-
68-
$violations = $validator->validateValue($input, $constraint);
69-
70-
Again, the validator returns the list of violations.
49+
The validator returns the list of violations.
7150

7251
Retrieving a Validator Instance
7352
-------------------------------

validation/raw_values.rst

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,34 @@ looks like this::
4646
// ...
4747
}
4848

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
5050
the constraint object that you want to validate that value against. A full
5151
list of the available constraints - as well as the full class name for each
5252
constraint - is available in the :doc:`constraints reference </reference/constraints>`
5353
section.
5454

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+
5577
The ``validate()`` method returns a :class:`Symfony\\Component\\Validator\\ConstraintViolationList`
5678
object, which acts just like an array of errors. Each error in the collection
5779
is a :class:`Symfony\\Component\\Validator\\ConstraintViolation` object,

0 commit comments

Comments
 (0)