/**
  * Validate value, validates as SQL date or SQL date
  * @see \Phramework\Validate\ValidateResult for ValidateResult object
  * @param  mixed $value Value to validate
  * @return ValidateResult
  * @todo set errorObject
  */
 public function validate($value)
 {
     //Use string's validator
     $return = parent::validate($value);
     //Apply additional rules
     if ($return->status === true && preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})$/', $value, $matches)) {
         if (checkdate($matches[2], $matches[3], $matches[1])) {
             $timestamp = strtotime($value);
             //validate formatMinimum
             if ($this->formatMinimum !== null && $timestamp < strtotime($this->formatMinimum)) {
                 $failure = 'formatMinimum';
                 goto error;
             }
             //validate formatMaximum
             if ($this->formatMaximum !== null && $timestamp > strtotime($this->formatMaximum)) {
                 $failure = 'formatMaximum';
                 goto error;
             }
             //Set status to success
             $return->status = true;
             return $return;
         }
     }
     $failure = 'failure';
     error:
     $return->status = false;
     $return->errorObject = new IncorrectParametersException([['type' => static::getType(), 'failure' => $failure]]);
     return $return;
 }
Exemple #2
0
 /**
  * Validate value
  * @see \Phramework\Validate\ValidateResult for ValidateResult object
  * @see https://secure.php.net/manual/en/filter.filters.validate.php
  * @param  mixed $value Value to validate
  * @return ValidateResult
  */
 public function validate($value)
 {
     //Use string's validator
     $return = parent::validate($value);
     //Apply additional rules
     if ($return->status == true) {
         if (filter_var($value, FILTER_VALIDATE_URL) === false) {
             //error
             $return->status = false;
             $return->errorObject = new IncorrectParametersException([['type' => static::getType(), 'failure' => 'format']]);
         }
     }
     return $return;
 }
 public function __construct($minLength = 0, $maxLength = null)
 {
     parent::__construct($minLength, $maxLength, static::getUsernamePattern());
 }