Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 06f67b4

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

File tree

Expand file treeCollapse file tree

2 files changed

+24
-23
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+24
-23
lines changed

‎components/validator.rst

Copy file name to clipboardExpand all lines: components/validator.rst
+1-22Lines 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

Copy file name to clipboardExpand all lines: validation/raw_values.rst
+23-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.