Exemplo n.º 1
0
 /**
  * Verify parameter value
  * @param $value
  * @return bool
  * @throws Exception
  */
 public static function verify($value)
 {
     switch (static::type) {
         case 'file':
             if (!isset($value['error']) or $value['error'] !== UPLOAD_ERR_OK) {
                 return false;
             }
             return true;
         case 'files':
             if (!is_array($value) or empty($value)) {
                 return false;
             }
             foreach ($value as $fileData) {
                 if ($fileData['error'] === UPLOAD_ERR_OK) {
                     return true;
                 }
             }
             return false;
         case 'data':
             return true;
     }
     if (is_array($value) or is_object($value)) {
         return false;
     }
     $value = self::canonicalize($value);
     switch (static::type) {
         case 'string':
             return is_string($value);
         case 'int':
             return filter_var($value, FILTER_VALIDATE_INT) or $value === '0';
         case 'float':
             $value = str_replace(',', '.', $value);
             return false !== filter_var($value, FILTER_VALIDATE_FLOAT) ? true : false;
         case 'url':
             // TODO: заменить этот фильтр на ESAPI
             return filter_var($value, FILTER_VALIDATE_URL);
         case 'email':
             return Filter\Email::validate($value);
         case 'ip':
             return filter_var($value, FILTER_VALIDATE_IP);
         case 'datetime':
             return Filter\Datetime::validate($value);
         case self::TYPE_DATE:
             return Filter\Date::validate($value);
         case 'phone':
             return Filter\Phone::validate($value);
         case 'bankcard':
             return Filter\Bankcard::validate($value);
         default:
             throw new Exception('Can\'t check param of type: ' . static::type);
     }
 }
Exemplo n.º 2
0
 /**
  * Verify e-mail
  * @param bool|false $fast
  * @return null|string
  */
 private function verifyEmail($fast = false)
 {
     // check e-mail
     if (!$this->ignoreEmpty) {
         if ($this->email === '') {
             return $this->failures['email'] = self::REGISTER_EMAIL_EMPTY;
         } elseif (!Email::validate($this->email)) {
             return $this->failures['email'] = self::REGISTER_EMAIL_INVALID;
         } elseif (!$fast and !self::isEmailAvailable($this->email)) {
             return $this->failures['email'] = self::REGISTER_EMAIL_EXISTS;
         } else {
             return $this->successful['email'] = self::REGISTER_EMAIL_OK;
         }
     } elseif ($this->email !== '') {
         if (!Email::validate($this->email)) {
             return $this->failures['email'] = self::REGISTER_EMAIL_INVALID;
         } elseif (!$fast and !self::isEmailAvailable($this->email)) {
             return $this->failures['email'] = self::REGISTER_EMAIL_EXISTS;
         }
     }
     return null;
 }