Drupal investigation

IsFalseValidator.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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\Context\ExecutionContextInterface;
  12. use Symfony\Component\Validator\Constraint;
  13. use Symfony\Component\Validator\ConstraintValidator;
  14. use Symfony\Component\Validator\Exception\UnexpectedTypeException;
  15. /**
  16. * @author Bernhard Schussek <bschussek@gmail.com>
  17. */
  18. class IsFalseValidator extends ConstraintValidator
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function validate($value, Constraint $constraint)
  24. {
  25. if (!$constraint instanceof IsFalse) {
  26. throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\IsFalse');
  27. }
  28. if (null === $value || false === $value || 0 === $value || '0' === $value) {
  29. return;
  30. }
  31. if ($this->context instanceof ExecutionContextInterface) {
  32. $this->context->buildViolation($constraint->message)
  33. ->setParameter('{{ value }}', $this->formatValue($value))
  34. ->setCode(IsFalse::NOT_FALSE_ERROR)
  35. ->addViolation();
  36. } else {
  37. $this->buildViolation($constraint->message)
  38. ->setParameter('{{ value }}', $this->formatValue($value))
  39. ->setCode(IsFalse::NOT_FALSE_ERROR)
  40. ->addViolation();
  41. }
  42. }
  43. }