Validates a creditcard belongs to a specified scheme.
mixed $value:
Constraint $constraint:
Overrides ConstraintValidatorInterface::validate
public function validate($value, Constraint $constraint) {
if (null === $value || '' === $value) {
return;
}
if (!is_numeric($value)) {
$this->context
->addViolation($constraint->message);
return;
}
$schemes = array_flip((array) $constraint->schemes);
$schemeRegexes = array_intersect_key($this->schemes, $schemes);
foreach ($schemeRegexes as $regexes) {
foreach ($regexes as $regex) {
if (preg_match($regex, $value)) {
return;
}
}
}
$this->context
->addViolation($constraint->message);
}