Validates whether a value match or not given regexp pattern
@author Bernhard Schussek <bschussek@gmail.com> @author Joseph Bielawski <stloyd@gmail.com>
@api
Expanded class hierarchy of RegexValidator
class RegexValidator extends ConstraintValidator {
/**
* {@inheritDoc}
*/
public function validate($value, Constraint $constraint) {
if (null === $value || '' === $value) {
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
$value = (string) $value;
if ($constraint->match xor preg_match($constraint->pattern, $value)) {
$this->context
->addViolation($constraint->message, array(
'{{ value }}' => $value,
));
}
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConstraintValidator:: |
protected | property | ||
ConstraintValidator:: |
public | function |
Initializes the constraint validator. Overrides ConstraintValidatorInterface:: |
1 |
RegexValidator:: |
public | function |
Checks if the passed value is valid. Overrides ConstraintValidatorInterface:: |