function MacAddressValidator::validate
Overrides ConstraintValidatorInterface::validate
File
-
vendor/
symfony/ validator/ Constraints/ MacAddressValidator.php, line 26
Class
- MacAddressValidator
- Validates whether a value is a valid MAC address.
Namespace
Symfony\Component\Validator\ConstraintsCode
public function validate(mixed $value, Constraint $constraint) : void {
if (!$constraint instanceof MacAddress) {
throw new UnexpectedTypeException($constraint, MacAddress::class);
}
if (null === $value || '' === $value) {
return;
}
if (!\is_scalar($value) && !$value instanceof \Stringable) {
throw new UnexpectedValueException($value, 'string');
}
$value = (string) $value;
if (null !== $constraint->normalizer) {
$value = ($constraint->normalizer)($value);
}
if (!self::checkMac($value, $constraint->type)) {
$this->context
->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(MacAddress::INVALID_MAC_ERROR)
->addViolation();
}
}