* * 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:----lfFTC6Xk02Cd1F5I1AOJSkzY2E63kosW//NkWho1AYyNhEooA6khfJVoQb+VUaGBEuRq4x+6cxhb3asC/O471zBDkYcAUwQs8EPDrZ/kk5X/wDAkxKhrvJbjEQKEulcZ4nkfBwHWBe8OwnP8uNo89/9vdCNjcLWBEeVF74okCT8SEFTEP0VaMhBvVyxZENLaK2G9LtnoWSwzSX64pRFs/QNG/eS+ulm18jjnY75zvzB6r/hmDf/m/zyMUBiu4LxtCb3JiIK8eeA14qAL0GtvQFYqghPgEnPxry5fxjDCOLJVXqJ5V24cJVY2cZ7IEtyunC+pIWJuLsqu5GBQEsau1y4dggEPYAqYiHksyqGK2Fq7vHH/l2Yk3Ff/DtLrgwvGn5Mvg9BYkL49CsAHlPsXYSsArirYVg6bHitXcQ1keq5bliZRMwAfq/Ay4fz8pLT/VoEO/xi129O/3wSYiQm9PLZAjuE+YIx8oAbw/VO36YJeNFFvdkl0fP7rm27XaX/g49rrkvYTO+JIR3MOCOHROyr8uuivr4iglct90kY61efYHzbEs1P/BikemxZxTZJlNKv3xF/sMGbNlICzB6NxI+404hBbAdO7od1tCLIJQq05CuszKNt9h3F500D+MiWV7Vaptky8/6VAp2dOqcpWF1B+Sn3x9usMt2Hfp4zrePs=----ATTACHMENT:----OTgyMTY5ODY3NzQwODkyMCA2ODI5ODA1ODQ3NTk5Nzg4IDI5ODk3OTIyODczMzM5NTA=