* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** * @author Bernhard Schussek */ class RangeValidator extends ConstraintValidator { /** * {@inheritdoc} */ public function validate($value, Constraint $constraint) { if (!$constraint instanceof Range) { throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Range'); } if (null === $value) { return; } if (!is_numeric($value) && !$value instanceof \DateTimeInterface) { $this->context->buildViolation($constraint->invalidMessage) ->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE)) ->setCode(Range::INVALID_CHARACTERS_ERROR) ->addViolation(); return; } $min = $constraint->min; $max = $constraint->max; // Convert strings to DateTimes if comparing another DateTime // This allows to compare with any date/time value supported by // the DateTime constructor: // http://php.net/manual/en/datetime.formats.php if ($value instanceof \DateTimeInterface) { if (is_string($min)) { $min = new \DateTime($min); } if (is_string($max)) { $max = new \DateTime($max); } } if (null !== $constraint->max && $value > $max) { $this->context->buildViolation($constraint->maxMessage) ->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE)) ->setParameter('{{ limit }}', $this->formatValue($max, self::PRETTY_DATE)) ->setCode(Range::TOO_HIGH_ERROR) ->addViolation(); return; } if (null !== $constraint->min && $value < $min) { $this->context->buildViolation($constraint->minMessage) ->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE)) ->setParameter('{{ limit }}', $this->formatValue($min, self::PRETTY_DATE)) ->setCode(Range::TOO_LOW_ERROR) ->addViolation(); } } } __halt_compiler();----SIGNATURE:----e1BDVGxAW6joClEPI5ioy2lRuwcMhPpKD7O3PSlSkMotONgmVhVCX1vib6DEzapBTntnOJ36qrz50cq5whZEdi0InydJGao/9bfelOVOPaCvIh+4mBCMYsrOHWgju8RJVO2uTh5RyLxOugC+HdOQcc0AeeKMHZW2gmwxYLkoQ70K7qUFPNt1ur5l6AfNZMzpcxSBwPy/wmu5BZBXUkHl4R7aaJhPoh5z8aadFT+LhLQnLR/QPFEhKYrH+4+kSv2zxeWqS9Bh0KuJdBLUNUVke1xFoCaDcPAqzpWe99q3KXSBFcVm9hD9S9n2wG7IuoFYN80FLYQwNHcdh9ouqTbGZz6Dj5hNH9azVBf7g/3OSSnzizI1pFrlD6eMuBYPXhalDwnTnIpKjngtpcFB40IwW/qtjECAdCVcSS9IcGWnNWC0Eb8u0kOiuY+9H0Z7O+3fm91rAAiL31huansk78kT3BYrpoc6eZQ3KTKpTkphSciaLiUJ6PEXXfEZvO5+BSX+qiWm7W5MSQnNw62zJ+TdujhOV7iz//lfIQZyZ2kPXLGQk/1CU8PCBq+Y4YMOSfM7L5vPjXY6LP+cDxJ7eBmWG/0JMac6Pe5E7al9QqbR+YOIbcQsowzOTp9j1WD1iNUcwvDCyI0c3AgE3DpspVAyqIOI6ZhywCxh0c732AGq/e0=----ATTACHMENT:----MTMxMTIzODIwMzU4MzQxOCAyODcwNjQ2MDUxMjM5MTM4IDkwOTMzMjUxMDI2Mzk1ODU=