Symfony\Component\Validator\Constraints\DateValidator::isValid PHP Method

isValid() public method

public isValid ( $value, Constraint $constraint )
$constraint Symfony\Component\Validator\Constraint
    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]);
    }

Same methods

DateValidator::isValid ( mixed $value, Constraint $constraint ) : boolean

Usage Example

 /**
  * Checks if the passed value is a valid date and if the (i.e. in the past)
  *
  * @param mixed      $value      The value that should be validated
  * @param Constraint $constraint The constraint for the validation
  *
  * @return Boolean Whether or not the value is valid
  *
  * @api
  */
 public function isValid($value, Constraint $constraint)
 {
     if (parent::isValid($value, $constraint)) {
         if ($value instanceof \DateTime) {
             $tm = $value->getTimestamp();
         } else {
             $tm = mktime((string) $value);
         }
         if (mktime($constraint->dateMax) > $tm) {
             return true;
         }
         $this->setMessage($constraint->message, array('{{ value }}' => $value, '{{ dateMax }}' => $constraint->dateMax));
     }
     return false;
 }
All Usage Examples Of Symfony\Component\Validator\Constraints\DateValidator::isValid
DateValidator