BlankValidator.php 1014 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. /**
  14. * @api
  15. */
  16. class BlankValidator extends ConstraintValidator
  17. {
  18. /**
  19. * Checks if the passed value is valid.
  20. *
  21. * @param mixed $value The value that should be validated
  22. * @param Constraint $constraint The constraint for the validation
  23. *
  24. * @return Boolean Whether or not the value is valid
  25. *
  26. * @api
  27. */
  28. public function isValid($value, Constraint $constraint)
  29. {
  30. if ('' !== $value && null !== $value) {
  31. $this->setMessage($constraint->message, array('{{ value }}' => $value));
  32. return false;
  33. }
  34. return true;
  35. }
  36. }