コード例 #1
0
 /**
  * To validate the form result that follow rules
  * @param  int $id
  * @param  string $rule
  * @param  string $errorType
  * @return boolean
  */
 public function validate($id = null, $rule = 'updateRules', $errorType = 'error')
 {
     if ($id !== null) {
         if (isset($this->validator->{$rule})) {
             $this->validator->setRule($rule);
         }
         return $this->validator->setUnique($id)->valid($this->getInput(), $errorType);
     }
     return $this->validator->valid($this->getInput(), $errorType);
 }
コード例 #2
0
 protected function validateIt($input = '')
 {
     $map = $this->getPattern();
     $validableAttrs = $this->validableHasToArray() ? $this->validable->toArray(true) : get_object_vars($this->validable);
     if (!empty($validableAttrs)) {
         foreach ($validableAttrs as $attr => $val) {
             $pattern = $map->getProperty(ucfirst($attr));
             $attrName = $pattern->getName();
             $attrType = $pattern->getType();
             $attrSize = $pattern->getSize();
             if ($attrType != 'Any' && $attrType != null) {
                 if (null != $attrSize && gettype($val) == $attrType && strlen($val . '') > $attrSize) {
                     $this->messages[] = "Size of {$attrName} exceeds the expected size of {$attrSize}!";
                 }
             }
         }
     } else {
         $this->messages[] = 'Could not get the array from ValidableInterface!';
     }
     // validation return
     return sizeof($this->messages) == 0;
 }