You are here

public function IsFalseValidator::validate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/validator/Constraints/IsFalseValidator.php \Symfony\Component\Validator\Constraints\IsFalseValidator::validate()

Checks if the passed value is valid.

Parameters

mixed $value The value that should be validated:

Constraint $constraint The constraint for the validation:

Overrides ConstraintValidatorInterface::validate

File

vendor/symfony/validator/Constraints/IsFalseValidator.php, line 27

Class

IsFalseValidator
@author Bernhard Schussek <bschussek@gmail.com>

Namespace

Symfony\Component\Validator\Constraints

Code

public function validate($value, Constraint $constraint) {
  if (!$constraint instanceof IsFalse) {
    throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\IsFalse');
  }
  if (null === $value || false === $value || 0 === $value || '0' === $value) {
    return;
  }
  if ($this->context instanceof ExecutionContextInterface) {
    $this->context
      ->buildViolation($constraint->message)
      ->setParameter('{{ value }}', $this
      ->formatValue($value))
      ->addViolation();
  }
  else {
    $this
      ->buildViolation($constraint->message)
      ->setParameter('{{ value }}', $this
      ->formatValue($value))
      ->addViolation();
  }
}