Beispiel #1
0
 /**
  * Execute la suite de tests.
  * 
  * @param mixed $void Ne sert à rien. Ne pas utiliser.
  * @return null|boolean Si vaut null, cela signifie que la valeur à tester n'existe pas.<br/>
  * Vaut TRUE ou FALSE selon la réussite de la suite des assertions.
  */
 public function validate($void = '')
 {
     if ($this->_bReturnNull) {
         return null;
     }
     return parent::validate($this->_mValueToTest);
 }
 /**
  * Validate a field's value with a given $rule
  * 
  * @param $value  mixed  Value to validate
  * @param $rule  mixed  Rule(s) to use for validation
  * @return bool
  */
 public static function validateField($value, $rule)
 {
     // only validate non-empty fields
     if ($value == "") {
         return true;
     }
     // validate
     $validator = new Validator();
     // create rules
     if (!is_array($rule)) {
         $validator->addRule(Validator::buildRule($rule));
     } else {
         foreach ($rule as $rule_key => $params) {
             $params = Helper::ensureArray($params);
             $validator->addRule(Validator::buildRule($rule_key, $params));
         }
     }
     return $validator->validate($value);
 }
Beispiel #3
0
 /**
  * Smart method to process fields, regardless of data type
  *
  * @param string  $field  Field to validate
  * @param mixed  $rule  Rule (or rules) to chain and validate with
  * @return bool
  */
 private function handleValidationRule($field, $rule)
 {
     if ($field == '') {
         return true;
     }
     # only validate non-empty fields.
     $spawn = new v();
     if (!is_array($rule)) {
         $spawn->addRule(v::buildRule($rule));
     } else {
         foreach ($rule as $rule_key => $params) {
             $params = !is_array($params) ? (array) $params : $params;
             # make sure params are an array
             $spawn->addRule(v::buildRule($rule_key, $params));
         }
     }
     return $spawn->validate($field);
 }