public function isValid($value, Constraint $constraint)
{
if (null === $value || '' === $value) {
return true;
}
if ($value instanceof \DateTime) {
return true;
}
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->setMessage($constraint->message, array('{{ value }}' => $value));
return false;
}
return checkdate($matches[2], $matches[3], $matches[1]);
}