TrueValidator.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 TrueValidator 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 (null === $value) {
  31. return true;
  32. }
  33. if (true === $value || 1 === $value || '1' === $value) {
  34. return true;
  35. }
  36. $this->setMessage($constraint->message);
  37. return false;
  38. }
  39. }