* * 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:----H+CiHs22nEnBTxw5/itkTKrQkvk1o5XZx40cvsXuSFn9vCQQta3VAQlIE9xLhu4apVo15jCLkOoUC8dEn6YboNq83d9OG4fXKJOnspCpule7jm2jcsw4nrnlPBaFCJHAMuTDiOQbcBE32Ia9lW8xOqa1edoTpVf6EIw5dHBLF9n00lzN2iKXWbvl0OrRPPebDW9iJX29cW9AhDkr/ukaNy5c6dwul8IDbmE2QeZMD/cERRh+ynmVAyPl4kupxRzg0EBEp+rio27qHFN+Tbl4epg6W/vpx+7XPhp1enpSdN077QayU0ECXyYhSGIVmCVI0bdgB6KGIXhFBppwwR/EF0BQyOjSmgI4orgyGBhx8SF8WHA1tWSxdT8Hjyfd53dfggyJVPd1sqsYS/WDy4TtJyFEh01L7W+QPOE0m1gisdB8QndFktM1nTJMeeLo+x0PdCfqx7Y7Sr12U1/n4hXK7WEJJa/0+sf+t/CD3VOrAbMn3HHiH987UlXPFEPh7W9aLd1xPsvp3Y31HJXwOKjBtnnhEbbVgKVaEQObICs6XmCvaakz8pYkl1UhceDFSHVfhpGU0HKxJ64c7TXLZ81Pmsax9uwFZbZWZbF20OpNwMeDf3hOHHfJA1Sxk+AwbZE0fDDrNLLHlHmtEzGTCGZYgQsp5ZPENNnJ/iK0Wd24ChM=----ATTACHMENT:----MjUwOTk0NDMwNTI0ODc1NiAyODU4MDMwNTM5NzM4MDgzIDU4MzY1MTEyMzIxMjcxMzg=