function NotBlankValidator::validate
Overrides ConstraintValidatorInterface::validate
File
-
vendor/
symfony/ validator/ Constraints/ NotBlankValidator.php, line 24
Class
- NotBlankValidator
- @author Bernhard Schussek <bschussek@gmail.com> @author Kévin Dunglas <dunglas@gmail.com>
Namespace
Symfony\Component\Validator\ConstraintsCode
public function validate(mixed $value, Constraint $constraint) : void {
if (!$constraint instanceof NotBlank) {
throw new UnexpectedTypeException($constraint, NotBlank::class);
}
if ($constraint->allowNull && null === $value) {
return;
}
if (\is_string($value) && null !== $constraint->normalizer) {
$value = ($constraint->normalizer)($value);
}
if (false === $value || !$value && '0' != $value) {
$this->context
->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(NotBlank::IS_BLANK_ERROR)
->addViolation();
}
}