コード例 #1
0
ファイル: NumsValidator.php プロジェクト: nicklos17/openapi
 /**
  * Executes the validation
  *
  * @param Phalcon\Validation $validator
  * @param string $attribute
  * @return boolean
  */
 public function validate($validator, $attribute)
 {
     $flag = true;
     $value = $validator->getValue($attribute);
     $errorCode = $this->getOption('code');
     if (!is_array($value)) {
         $message = '参数必须是数组';
         $validator->appendMessage(new Message($message, $attribute, 'Nums'));
         return false;
     }
     $countVal = count($value);
     $ruleMin = $this->getOption('min');
     $ruleMax = $this->getOption('max');
     if ($ruleMin == $ruleMax) {
         if ($countVal < $ruleMin) {
             $flag = false;
         }
     } else {
         if ($countVal < $ruleMin || $countVal > $ruleMax) {
             $flag = false;
         }
     }
     if (!$flag) {
         $message = $this->getOption('message');
         if (!$message) {
             $message = 'The num is not valid';
         }
         $validator->appendMessage(new Message($message, $attribute, 'Nums'));
         return false;
     }
     return true;
 }
コード例 #2
0
 /**
  * Executes the validation
  *
  * @param Phalcon\Validation $validator
  * @param string $attribute
  * @return boolean
  */
 public function validate($validator, $attribute)
 {
     $flag = true;
     $reqType = $validator->getValue($attribute);
     // 待校验的文件集合
     $fileType = $this->getOption('filetype');
     // 合法的文件类型集合
     $errorCode = $this->getOption('code');
     foreach ($reqType as $file) {
         $extArr = explode('.', $file);
         $ext = array_pop($extArr);
         if (!in_array($ext, $fileType)) {
             $flag = false;
             break;
         }
     }
     if (!$flag) {
         $message = $this->getOption('message');
         if (!$message) {
             $message = 'The filetype is not valid';
         }
         $validator->appendMessage(new Message($message, $attribute, 'filetype'));
         return false;
     }
     return true;
 }
コード例 #3
0
 /**
  * Executes the validation
  *
  * @param Phalcon\Validation $validator
  * @param string $attribute
  * @return boolean
  */
 public function validate($validator, $attribute)
 {
     $value = $validator->getValue($attribute);
     if (!filter_var($value, FILTER_VALIDATE_URL)) {
         $message = $this->getOption('message');
         if (!$message) {
             $message = self::INVALID_URL;
         }
         $validator->appendMessage(new Message($message, $attribute, 'Url'));
         return false;
     }
     return true;
 }
コード例 #4
0
 /**
  * Executes the validation
  *
  * @param Phalcon\Validation $validator
  * @param string $attribute
  * @return boolean
  */
 public function validate($validator, $attribute)
 {
     $value = $validator->getValue($attribute);
     if (filter_var($value, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)) {
         $message = $this->getOption('message');
         if (!$message) {
             $message = 'The IP is not valid';
         }
         $validator->appendMessage(new Message($message, $attribute, 'Ip'));
         return false;
     }
     return true;
 }
コード例 #5
0
 /**
  * Executes the uniqueness validation
  *
  * @param  Phalcon\Validation $validator
  * @param  string             $attribute
  * @return boolean
  */
 public function validate($validator, $attribute)
 {
     $table = $this->getOption('table');
     $column = $this->getOption('column');
     $result = $this->db->fetchOne(sprintf('SELECT COUNT(*) as count FROM %s WHERE %s = ?', $table, $column), \Phalcon\Db::FETCH_ASSOC, array($validator->getValue($attribute)));
     if ($result['count']) {
         $message = $this->getOption('message');
         if (null === $message) {
             $message = 'Already taken. Choose another!';
         }
         $validator->appendMessage(new Message($message, $attribute, 'Uniqueness'));
         return false;
     }
     return true;
 }
コード例 #6
0
ファイル: Numericality.php プロジェクト: riquedesimone/biko
 /**
  * Executes the validation
  *
  * @param Phalcon\Validation $validator
  * @param string $attribute
  * @return boolean
  */
 public function validate($validator, $attribute)
 {
     $value = $validator->getValue($attribute);
     if ($value !== null && $value !== '') {
         if (!is_numeric($value) || !preg_match('/^[0-9\\.]+$/', $value)) {
             $message = $this->getOption('message');
             if ($message) {
                 $validator->appendMessage(new Message($message, $attribute, 'Numericality'));
             } else {
                 $validator->appendMessage(new Message('This field must be a number', $attribute, 'Numericality'));
             }
             return false;
         }
     }
     return true;
 }