This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Validator/Constraints/AllValidator.php
Bernhard Schussek 054f1b5536 Merge branch '2.3' into 2.4
* 2.3:
  [Validator] Backported constraint validator tests from 2.5
  Fix toolbar vertical alignment.
  [HttpFoundation] MongoDbSessionHandler supports auto expiry via configurable expiry_field
  [FrameworkBundle] add missing attribute to XSD
  Allow basic auth in url. Improve regex. Add tests.
  fix typos and syntax in Profiler controller method comments
  remove volatile tests
  [Console] fixed style creation when providing an unknown tag option
  [Validator] Convert objects to string in comparison validators. Reapplies 6cf5e0812e
  [HttpFoundation] Update QUERY_STRING when overrideGlobals

Conflicts:
	src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueValidatorTest.php
	src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
	src/Symfony/Component/Validator/Constraints/AllValidator.php
	src/Symfony/Component/Validator/Constraints/CollectionValidator.php
	src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php
	src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php
	src/Symfony/Component/Validator/Tests/Constraints/EqualToValidatorTest.php
	src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php
	src/Symfony/Component/Validator/Tests/Constraints/GreaterThanValidatorTest.php
	src/Symfony/Component/Validator/Tests/Constraints/IdenticalToValidatorTest.php
	src/Symfony/Component/Validator/Tests/Constraints/ImageValidatorTest.php
	src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorTest.php
	src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorTest.php
	src/Symfony/Component/Validator/Tests/Constraints/NotEqualToValidatorTest.php
	src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToValidatorTest.php
	src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php
2014-08-14 16:51:32 +02:00

60 lines
1.7 KiB
PHP

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class AllValidator extends ConstraintValidator
{
/**
* {@inheritdoc}
*/
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;
$group = $context->getGroup();
if ($context instanceof ExecutionContextInterface) {
$validator = $context->getValidator()->inContext($context);
foreach ($value as $key => $element) {
$validator->atPath('['.$key.']')->validate($element, $constraint->constraints, $group);
}
} else {
// 2.4 API
foreach ($value as $key => $element) {
$context->validateValue($element, $constraint->constraints, '['.$key.']', $group);
}
}
}
}