Skip to content

Commit

Permalink
[Validator] Adding support for Closure in CallbackValidator
Browse files Browse the repository at this point in the history
Usage:
$formBuilder = $this->get('form.factory')
            ->createBuilder('form');
$formBuilder->setAttribute('validation_constraint', new Callback(array("methods"=>array(
    'validate' => function ($data, $context) use ($elements) {
       // logic to add violations depending on the elements
    }
))));
  • Loading branch information
johnwards committed May 10, 2011
1 parent 3854d34 commit d96e2c5
Showing 1 changed file with 1 addition and 1 deletion.
Expand Up @@ -45,7 +45,7 @@ public function isValid($object, Constraint $constraint)
$propertyPath = $context->getPropertyPath();

foreach ($methods as $method) {
if (is_array($method)) {
if (is_array($method) || $method instanceof \Closure) {
if (!is_callable($method)) {
throw new ConstraintDefinitionException(sprintf('"%s::%s" targeted by Callback constraint is not a valid callable', $method[0], $method[1]));
}
Expand Down

0 comments on commit d96e2c5

Please sign in to comment.