* * 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 TimeValidator extends ConstraintValidator { const PATTERN = '/^(\d{2}):(\d{2}):(\d{2})$/'; /** * Checks whether a time is valid. * * @param int $hour The hour * @param int $minute The minute * @param int $second The second * * @return bool Whether the time is valid * * @internal */ public static function checkTime($hour, $minute, $second) { return $hour >= 0 && $hour < 24 && $minute >= 0 && $minute < 60 && $second >= 0 && $second < 60; } /** * {@inheritdoc} */ public function validate($value, Constraint $constraint) { if (!$constraint instanceof Time) { throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Time'); } if (null === $value || '' === $value || $value instanceof \DateTimeInterface) { return; } if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) { throw new UnexpectedTypeException($value, 'string'); } $value = (string) $value; if (!preg_match(static::PATTERN, $value, $matches)) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setCode(Time::INVALID_FORMAT_ERROR) ->addViolation(); return; } if (!self::checkTime($matches[1], $matches[2], $matches[3])) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setCode(Time::INVALID_TIME_ERROR) ->addViolation(); } } } __halt_compiler();----SIGNATURE:----WlUyGLClqojb/eipUGDRmJjn+lwVBniCr2LYj+r7fYR01GX0QyE5uy/TAiGzQ+wWMmF6VuFQDX+5b+59isR9u7h93A5bBuTqdUN3RcbtS0B1LoLz+3QgMt85jbknAc0p0TmGySf1FJyd0VMr3ZXBB6pMWI6x/gmU1SN4oZ+c7+qAQzW24TXerD/i1FT5qkVJLGFiASn5Rn3/1wB0XzLjPiblnH3pV/BZpyRjG7gSPZbtAyImZTtF5haGigCBk1VCSMIYD9mW3FXNpRsUHPq6x9TY5g700i4yG1QbIrgevad+Io49uHYLA2k6Wp6SRojuyGBpk/ozl8aXa9bad999P2qKBsfe1Z/m5b+ZiBUKYbxhSd/JAI2vGf3QZrCycrVEPA4ohPvNzy6+AMjjKPSrOx2zLPvNEb+zB3isnExrUGpvb9+8ze+JKi1abiHTVqEK5ODW9AcNKQw/9t0gj2qx9ydq4n9Su0h5fkkxGGtO6sx0WTSM8Fokt74OOKpAKLOsQ/2BejHL/TB6rx9cmpSre5d9fuLLvGgmXpaTq6Zumr2g9miOwPSVX+6ewO1IZwzrrC4mRnfviowz6s4TeaUBEuNRjrMybEXvA7Pba7kvUSYSZi2XZOEQT3vipqXSpmc9u6fdTbw1W9p7phDYNooex+NteqZ9+WxZAo7ZZa6PXyU=----ATTACHMENT:----MTE1MDA4MDgyMzI0MDMzMCA1NDE5MTEzMjc0MjEwMTMgOTQ5MTM0MDE1NzEyNTQ2MA==