TrueValidator.php 752 B

123456789101112131415161718192021222324252627282930313233
  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. class TrueValidator extends ConstraintValidator
  14. {
  15. public function isValid($value, Constraint $constraint)
  16. {
  17. if (null === $value) {
  18. return true;
  19. }
  20. if (true === $value || 1 === $value || '1' === $value) {
  21. return true;
  22. }
  23. $this->setMessage($constraint->message);
  24. return false;
  25. }
  26. }