class RegexValidator

Validates whether a value match or not given regexp pattern

@author Bernhard Schussek <bschussek@gmail.com> @author Joseph Bielawski <stloyd@gmail.com>

@api

Hierarchy

Expanded class hierarchy of RegexValidator

1 file declares its use of RegexValidator
RegexValidatorTest.php in drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php

File

drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Constraints/RegexValidator.php, line 26

Namespace

Symfony\Component\Validator\Constraints
View source
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,
      ));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConstraintValidator::$context protected property
ConstraintValidator::initialize public function Initializes the constraint validator. Overrides ConstraintValidatorInterface::initialize 1
RegexValidator::validate public function Checks if the passed value is valid. Overrides ConstraintValidatorInterface::validate