Skip to content

Instantly share code, notes, and snippets.

@baldurrensch
Created January 2, 2013 18:49
Show Gist options
  • Save baldurrensch/4436827 to your computer and use it in GitHub Desktop.
Save baldurrensch/4436827 to your computer and use it in GitHub Desktop.
How to use the All Validator
<?php
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\All;
// This is reduced to the bare minimum. Missing Namespace and other imports
class DemoController extends Controller
{
function testAction()
{
$testArr = array(
'[email protected]',
'invalid@gmail'
);
$emailConstraint = new Email();
$collectionConstraint = new All(array($emailConstraint));
$errorList = $this->get('validator')->validateValue(
$testArr,
$collectionConstraint
);
echo "<pre>";
print_r($errorList);
}
}
Symfony\Component\Validator\ConstraintViolationList Object
(
[violations:protected] => Array
(
[0] => Symfony\Component\Validator\ConstraintViolation Object
(
[messageTemplate:protected] => This value is not a valid email address.
[messageParameters:protected] => Array
(
[{{ value }}] => invalid@gmail
)
[messagePluralization:protected] =>
[root:protected] =>
[propertyPath:protected] => [1]
[invalidValue:protected] => invalid@gmail
[code:protected] =>
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment