4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Validator\Constraints;
14 use Symfony\Component\Validator\Constraint;
15 use Symfony\Component\Validator\ConstraintValidator;
16 use Symfony\Component\Validator\Context\ExecutionContextInterface;
17 use Symfony\Component\Validator\Exception\UnexpectedTypeException;
20 * @author Bernhard Schussek <bschussek@gmail.com>
22 class AllValidator extends ConstraintValidator
27 public function validate($value, Constraint $constraint)
29 if (!$constraint instanceof All) {
30 throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\All');
33 if (null === $value) {
37 if (!is_array($value) && !$value instanceof \Traversable) {
38 throw new UnexpectedTypeException($value, 'array or Traversable');
41 $context = $this->context;
43 if ($context instanceof ExecutionContextInterface) {
44 $validator = $context->getValidator()->inContext($context);
46 foreach ($value as $key => $element) {
47 $validator->atPath('['.$key.']')->validate($element, $constraint->constraints);
51 foreach ($value as $key => $element) {
52 $context->validateValue($element, $constraint->constraints, '['.$key.']');