10000 [Validator] Added array validation example to raw values by wouterj · Pull Request #7805 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

[Validator] Added array validation example to raw values #7805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 21, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
missing constraint example from the old readme
  • Loading branch information
CoolGoose authored and wouterj committed Apr 15, 2017
commit c8b6b457bc9da550a3200683176d2121065b019c
25 changes: 25 additions & 0 deletions components/validator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,31 @@ characters long::
echo $violation->getMessage().'<br>';
}
}

Validation of arrays is possible using the `Collection` constraint::


use Symfony\Component\Validator\Validation;
use Symfony\Component\Validator\Constraints as Assert;

$validator = Validation::createValidator();

$constraint = new Assert\Collection(array(
'name' => new Assert\Collection(array(
'first_name' => new Assert\Length(array('min' => 101)),
'last_name' => new Assert\Length(array('min' => 1)),
)),
'email' => new Assert\Email(),
'simple' => new Assert\Length(array('min' => 102)),
'gender' => new Assert\Choice(array(3, 4)),
'file' => new Assert\File(),
'password' => new Assert\Length(array('min' => 60)),
));

$violations = $validator->validateValue($input, $constraint);


Again, the validator returns the list of violations.

Retrieving a Validator Instance
-------------------------------
Expand Down
0