Valitron\Validator::rules PHP Method

rules() public method

Convenience method to add multiple validation rules with an array
public rules ( array $rules )
$rules array
    public function rules($rules)
    {
        foreach ($rules as $ruleType => $params) {
            if (is_array($params)) {
                foreach ($params as $innerParams) {
                    array_unshift($innerParams, $ruleType);
                    call_user_func_array(array($this, 'rule'), $innerParams);
                }
            } else {
                $this->rule($ruleType, $params);
            }
        }
    }

Usage Example

 /**
  * Method that validates fields of the entity based on its restrictions
  */
 protected function validateFields()
 {
     $validator = new Validator($this->data, [], 'en');
     //@todo: if use external i18n library?
     if ($this->action == 'new') {
         $validator->rules(array_merge($this->rulesNew, $this->rulesGlobal));
     } else {
         $validator->rules(array_merge($this->rulesModify, $this->rulesGlobal));
     }
     if (!$validator->validate()) {
         $this->errors = array_merge($this->errors, $validator->errors());
     }
 }
All Usage Examples Of Valitron\Validator::rules