isValid() public method

public isValid ( $value, Constraint $constraint )
$constraint Symfony\Component\Validator\Constraint
コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 public function isValid($value, Constraint $constraint)
 {
     if (parent::isValid($value, $constraint)) {
         if ($value instanceof \DateTime) {
             $tm = $value->getTimestamp();
         } else {
             preg_match(self::PATTERN_BIRTHDAY, string($value), $matches);
             $tm = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
         }
         if (time() > $tm) {
             return true;
         }
         $this->setMessage($constraint->messageBirthday, array('{{ value }}' => $value));
     }
     return false;
 }