ValidValidator.php 1006 B

1234567891011121314151617181920212223242526272829303132333435363738
  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 Christian Flothmann <christian.flothmann@sensiolabs.de>
  16. */
  17. class ValidValidator extends ConstraintValidator
  18. {
  19. public function validate($value, Constraint $constraint)
  20. {
  21. if (!$constraint instanceof Valid) {
  22. throw new UnexpectedTypeException($constraint, Valid::class);
  23. }
  24. if (null === $value) {
  25. return;
  26. }
  27. $this->context
  28. ->getValidator()
  29. ->inContext($this->context)
  30. ->validate($value, null, $this->context->getGroup());
  31. }
  32. }