From ec2c8ae339ddaa3264682f92f13a09d03c95a86e Mon Sep 17 00:00:00 2001 From: Alexandru Bucur Date: Fri, 25 Nov 2016 10:39:15 +0200 Subject: [PATCH 1/2] missing constraint example from the old readme --- components/validator.rst | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/components/validator.rst b/components/validator.rst index 775be555513..29a6abcaa1f 100644 --- a/components/validator.rst +++ b/components/validator.rst @@ -45,6 +45,31 @@ characters long:: echo $violation->getMessage().'
'; } } + +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 ------------------------------- From 999f985f8d911bddc757f01377fad46de71bfd8c Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 25 Nov 2016 12:37:30 +0100 Subject: [PATCH 2/2] Fixed some syntax issues --- components/validator.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/components/validator.rst b/components/validator.rst index 29a6abcaa1f..b10b4e69b28 100644 --- a/components/validator.rst +++ b/components/validator.rst @@ -46,8 +46,7 @@ characters long:: } } -Validation of arrays is possible using the `Collection` constraint:: - +Validation of arrays is possible using the ``Collection`` constraint:: use Symfony\Component\Validator\Validation; use Symfony\Component\Validator\Constraints as Assert; @@ -68,7 +67,6 @@ Validation of arrays is possible using the `Collection` constraint:: $violations = $validator->validateValue($input, $constraint); - Again, the validator returns the list of violations. Retrieving a Validator Instance