CompoundValidator.php 960 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Validator\Constraints;
  11. use Symfony\Component\Validator\Constraint;
  12. use Symfony\Component\Validator\ConstraintValidator;
  13. use Symfony\Component\Validator\Exception\UnexpectedTypeException;
  14. /**
  15. * @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
  16. */
  17. class CompoundValidator extends ConstraintValidator
  18. {
  19. public function validate($value, Constraint $constraint)
  20. {
  21. if (!$constraint instanceof Compound) {
  22. throw new UnexpectedTypeException($constraint, Compound::class);
  23. }
  24. $context = $this->context;
  25. $validator = $context->getValidator()->inContext($context);
  26. $validator->validate($value, $constraint->constraints);
  27. }
  28. }