class RangeValidator

@author Bernhard Schussek <bschussek@gmail.com>

Hierarchy

Expanded class hierarchy of RangeValidator

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

File

drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Constraints/RangeValidator.php, line 20

Namespace

Symfony\Component\Validator\Constraints
View source
class RangeValidator extends ConstraintValidator {

  /**
   * {@inheritDoc}
   */
  public function validate($value, Constraint $constraint) {
    if (null === $value) {
      return;
    }
    if (!is_numeric($value)) {
      $this->context
        ->addViolation($constraint->invalidMessage, array(
        '{{ value }}' => $value,
      ));
      return;
    }
    if (null !== $constraint->max && $value > $constraint->max) {
      $this->context
        ->addViolation($constraint->maxMessage, array(
        '{{ value }}' => $value,
        '{{ limit }}' => $constraint->max,
      ));
      return;
    }
    if (null !== $constraint->min && $value < $constraint->min) {
      $this->context
        ->addViolation($constraint->minMessage, array(
        '{{ value }}' => $value,
        '{{ limit }}' => $constraint->min,
      ));
    }
  }

}

Members

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