public function IsTrueValidator::validate in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/validator/Constraints/IsTrueValidator.php \Symfony\Component\Validator\Constraints\IsTrueValidator::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/ IsTrueValidator.php, line 27
Class
- IsTrueValidator
- @author Bernhard Schussek <bschussek@gmail.com>
Namespace
Symfony\Component\Validator\ConstraintsCode
public function validate($value, Constraint $constraint) {
if (!$constraint instanceof IsTrue) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\IsTrue');
}
if (null === $value) {
return;
}
if (true !== $value && 1 !== $value && '1' !== $value) {
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();
}
}
}