* * 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 DateValidator extends ConstraintValidator { const PATTERN = '/^(\d{4})-(\d{2})-(\d{2})$/'; /** * Checks whether a date is valid. * * @param int $year The year * @param int $month The month * @param int $day The day * * @return bool Whether the date is valid * * @internal */ public static function checkDate($year, $month, $day) { return checkdate($month, $day, $year); } /** * {@inheritdoc} */ public function validate($value, Constraint $constraint) { if (!$constraint instanceof Date) { throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Date'); } 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(Date::INVALID_FORMAT_ERROR) ->addViolation(); return; } if (!self::checkDate($matches[1], $matches[2], $matches[3])) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setCode(Date::INVALID_DATE_ERROR) ->addViolation(); } } } __halt_compiler();----SIGNATURE:----Cg3lMM3Bww2IFIhSOeFjmSInJ5Oy3sO70CG2F0rs2cdgP26IeQF28hNifxAekWFBj+HA0ZhuVhh+2POsImAHi2T08Z47OjsJCpXqxmyyCNjr0KhF+sWCTjxPqSBcIUR8xUVaR7CfsEZT72nIZzdP6zxy1FYBSO67TNFCP0Jy2RTmxOfeLLncVjBa99/jjfKdIe7xRp77HCqJy1g/9aSh06Xmr66YgRbZtFHE0M+hKDhgKnJ1kQfEP73h0WfFBljft9OclD2j52twv4owvm/a/gRnqvpxelIt1Yv2pqRDY6Zl2IeuWmo5qDUpITeEUl/Eh/8dktvYlr88nT/YmiaGrA/2CezBx2PD4P+WNw13zGFLCSe2JzIRoHPdPmxgCYgLla6nAyw0+7H7INM7b46wx64cMhF+mKzM0gUv8FmGO9volBvrHeN3Nm3TsmBzJh8uu8df4afUMSLPxN+87GAHCWzN6vpciw2tN3l/P44E+DOLz1V8AikTFDf35bR70zYhod1p5N/J8Tuhz5Jc9xNBHqIsthyUUwkrttSNe2RN57cO38rBlRq8eWSa3pbvGqOd8f/79gW1pE1JyFZq/mYfwBys4t11KJ5nv8VQx7XzIG/YvOXdJk92Jvo9/acVPMazYcr9WuEt+p53AtGxpKwgTYlv6LC0DJybDgGpjAU73ds=----ATTACHMENT:----NjYyNzI0NzY0NzE3NTYzOCA5Mjg1ODE4NTc0MzI2NTY4IDI2NDM1MjQ4NDMyNDI3MzA=