You are here

public function AllValidator::validate in Plug 7

Checks if the passed value is valid.

@api

Parameters

mixed $value The value that should be validated:

Constraint $constraint The constraint for the validation:

Overrides ConstraintValidatorInterface::validate

File

lib/Symfony/validator/Symfony/Component/Validator/Constraints/AllValidator.php, line 29

Class

AllValidator
@author Bernhard Schussek <bschussek@gmail.com>

Namespace

Symfony\Component\Validator\Constraints

Code

public function validate($value, Constraint $constraint) {
  if (!$constraint instanceof All) {
    throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\All');
  }
  if (null === $value) {
    return;
  }
  if (!is_array($value) && !$value instanceof \Traversable) {
    throw new UnexpectedTypeException($value, 'array or Traversable');
  }
  $context = $this->context;
  if ($context instanceof ExecutionContextInterface) {
    $validator = $context
      ->getValidator()
      ->inContext($context);
    foreach ($value as $key => $element) {
      $validator
        ->atPath('[' . $key . ']')
        ->validate($element, $constraint->constraints);
    }
  }
  else {

    // 2.4 API
    foreach ($value as $key => $element) {
      $context
        ->validateValue($element, $constraint->constraints, '[' . $key . ']');
    }
  }
}