@param array   $data
@param array   $rules
@param Closure $validationFailed
@param array   $messages
@param array   $customAttributes

@return array
509755
private function tryValidateData(
        array $data,
        array $rules,
        Closure $validationFailed,
        array $messages = [],
        array $customAttributes = []
    ) {
        $validator = $this->createValidator($data, $rules, $messages, $customAttributes);

        if ($validator->fails()) {
            call_user_func($validationFailed, $validator->errors()->getMessages());
        }
    }
931661
private function parseData(array $data)
    {
        $field = $data['field'];

        foreach ($data['policies'] as $rule => $policy) {
            $passes = call_user_func_array([new Rule(), $rule], [$field, $data['value'], $policy]);

            if (!$passes) {
                ErrorHandler::set(
                    str_replace(
                        [':attribute', ':policy', '_'],
                        [$field, $policy, ' '], $this->messages[$rule]), $field
                );
            }
        }
    }
45081
public function rules($rules = null, $messages = [])
    {
        if ($rules instanceof \Closure) {
            $this->rules = $rules;
        }

        if (is_array($rules)) {
            $thisRuleArr = array_filter(explode('|', $this->rules));

            $this->rules = array_merge($thisRuleArr, $rules);
        } elseif (is_string($rules)) {
            $rules = array_filter(explode('|', "{$this->rules}|$rules"));

            $this->rules = implode('|', $rules);
        }

        $this->validationMessages = $messages;

        return $this;
    }
1113049
public function make($data, $rules, $messages=[], $clean = true) {
      // parametros de los roles
      $param = [];
      $temp  = "";
      if($clean)
         $this->fails = null;

      foreach ($rules as $field => $rule) {
      // foreach ($data as $field => $value) {

         if(!isset($rules[$field])) continue;

         $value = @$data[$field];

         if(!is_array($value)) $value = trim($value);

         if(!is_array($rules[$field])) $rules[$field] = explode("|", $rules[$field]);

         foreach ($rules[$field] as $key_rol => $rol) {
            $rol = trim($rol);

            if (preg_match("/:/", $rol)) {
               if(preg_match("/regex/", $rol)) {
                  $temp_rol = explode(":", $rol);
                  $rol      = ($temp_rol[0]);
                  unset($temp_rol[0]);
                  $param[0]    = implode(':', @$temp_rol);
               } else{
                  $temp_rol = explode(":", $rol);
                  $rol      = ($temp_rol[0]);
                  unset($temp_rol[0]);
                  $param    = explode(",", implode(':', @$temp_rol));
               }
            }
            switch ($rol) {
               case 'accepted':
                  break;
               case 'active_url':
                  break;
               case 'after':
                  break;
               case 'alpha':
                  if ($value!='') {
                     // ASCII lATIN1
                     if (!preg_match('/^[a-zA-Zá-üÁ-Ü\s]*$/', $value)) {
                        $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'alpha_dash':
                  if ($value!='') {
                     // ASCII lATIN1
                     if (!preg_match("/^[0-9a-zA-Zá-üÁ-Ü\s_\-\.,\(\)]*$/", $value)) {
                        $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'alpha_num':
                  if ($value!='') {
                     // ASCII lATIN1
                     if (!preg_match("/^[0-9a-zA-Zá-üÁ-Ü\s\.]*$/", $value)) {
                        $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'array':
                  if ($value!='') {
                     if (!is_array($value)) {
                        $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'before':break;
               case 'between':
                  //    "numeric"            "file"            "string"          "array"
                  if (@$param[0]=='' || !is_numeric(@$param[0]) || !is_numeric(@$param[1])) throw new Exception(" El parametro del rol {$rol} es incorrecto ", 1);
                  if ($value!='') {
                     $len = $value;
                     if (is_array($value)) {
                        $len = count($value);
                     }elseif (!is_numeric($value)) {
                        $len = strlen($value);
                     }

                     if ($len < @$param[0]) {
                        $fail_max = true;
                     }

                     if ($len > @$param[1]) {
                        $fail_min = true;
                     }

                     if (!count($param) || @$fail_max || @$fail_min ) {
                        if (is_array($value)) {
                           $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol]['array'])));
                        }elseif (!is_numeric($value)) {
                           $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol]['string'])));
                        }else{
                           $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol]['numeric'])));
                        }

                        $temp = str_replace(":min", @$param[0]?@$param[0]:0, $temp);
                        $temp = str_replace(":max", @$param[1]?@$param[1]:0, $temp);
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'confirmed':break;
               case 'date':break;
               case 'date_format':
                  if (@$param[0]=='') throw new Exception(" El parametro del rol {$rol} es incorrecto ", 1);

                  if ($value!='') {
                     $format = date_parse_from_format(@$param[0], $value);

                     if ($format['error_count']) {

                        $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                        $temp = str_replace(":format", @$param[0]?@$param[0]:0, $temp);
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'different':
                  if (@$param[0]=='') throw new Exception(" El parametro del rol {$rol} es incorrecto ", 1);

                  $d = [
                     $field => $value,
                  ];
                  $r = [
                     $field => implode('|', $rules[@$param[0]]),
                  ];

                  $Validator = new Validator;
                  $v = $Validator->make($d,$r,@$messages);

                  if (count($v->fails) || strtolower($value)==strtolower($data[@$param[0]])) {
                     if (count($v->fails)) {
                        $this->fails["messages"][$field]   = $v->fails["messages"][$field];
                        $this->fails["failed"]  [$field]   = $v->fails["failed"]  [$field];
                     }else{
                        $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                        $temp = str_replace(":other", @$param[0], $temp);
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'digits':
                  if (!is_numeric(@$param[0])) throw new Exception(" El parametro del rol {$rol} es incorrecto ", 1);
                  if ($value!='') {
                     if (!preg_match("/^[0-9]*$/", $value) || !count($param) || strlen($value) != @$param[0]) {
                        $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                        $temp = str_replace(":digits",    @$param[0]?@$param[0]:0, $temp);
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'digits_between':
                  if (!is_numeric(@$param[0]) || !is_numeric(@$param[1])) throw new Exception(" El parametro del rol {$rol} es incorrecto ", 1);
                  if ($value!='') {
                     $len = strlen($value);

                     if ($len < @$param[0]) $fail_max = true;

                     if ($len > @$param[1]) $fail_min = true;

                     if (@$fail_max || @$fail_min ) {

                        $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));

                        $temp = str_replace(":min", @$param[0]?@$param[0]:0, $temp);
                        $temp = str_replace(":max", @$param[1]?@$param[1]:0, $temp);
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'email':
                  if ($value!='') {
                     $value=filter_var($value, FILTER_SANITIZE_EMAIL);
                     if(!filter_var($value, FILTER_VALIDATE_EMAIL)) {
                        $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'exists':break;
               case 'image':
                  if ($value!='') {
                     if (!preg_match("/.*(\.jpg)|(\.jpeg)|(\.png)|(\.bmp)|(\.gif)$/", $value)) {
                        $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'in':
                  if (@$param[0]=='') throw new Exception(" El parametro del rol {$rol} es incorrecto ", 1);
                  if ($value!='') {
                     if (!is_numeric(array_search(strtolower($value), array_map( function ($v){return strtolower($v);}, $param)))) {

                        $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                        $temp = str_replace(":values", implode(',', @$param), $temp);
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'integer':
                  if ($value!='') {
                     if (!preg_match("/^[0-9]*$/", $value)) {
                        $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'ip':
                  if ($value!='') {
                     if (!preg_match("/^([0-9]){1,3}\.([0-9]){1,3}\.([0-9]){1,3}\.([0-9]){1,3}$/", $value)) {
                        $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'max':
                  //    "numeric"            "file"            "string"          "array"
                  if (!is_numeric(@$param[0])) throw new Exception(" El parametro del rol {$rol} es incorrecto ", 1);
                  if ($value!='') {
                     $len = $value;
                     if (is_array($value)) {
                        $len = count($value);
                     }elseif (is_string($value)) {
                        $len = strlen($value);
                     }

                     if (!count($param) || ($len > @$param[0])) {
                        if (is_array($value)) {
                           $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol]['array'])));
                        }elseif (is_string($value)) {
                           $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol]['string'])));
                        }else{
                           $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol]['numeric'])));
                        }

                        $temp = str_replace(":max"      , @$param[0]?@$param[0]:0, $temp);
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'mimes':
                  if (@$param[0]=='') throw new Exception(" El parametro del rol {$rol} es incorrecto ", 1);

                  if ($value!='') {
                     $param = implode('|', $param);

                     if (!preg_match("/.*".$param."$/", $value)) {
                        $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                        $temp = str_replace(":values", str_replace('|', ',', @$param), $temp);
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'min':
                  //    "numeric"            "file"            "string"          "array"
                  if (!is_numeric(@$param[0])) throw new Exception(" El parametro del rol {$rol} es incorrecto ", 1);
                  if ($value!='') {
                     $len = $value;
                     if (is_array($value)) {
                        $len = count($value);
                     }elseif (is_string($value)) {
                        $len = strlen($value);
                     }
                     
                     if (!count($param) || ($len < @$param[0])) {
                        if (is_array($value)) {
                           $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol]['array'])));
                        }elseif (is_string($value)) {
                           $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol]['string'])));
                        }else{
                           $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol]['numeric'])));
                        }

                        $temp = str_replace(":min"      , @$param[0]?@$param[0]:0, $temp);
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'not_in':
                  if (!@$param[0]) throw new Exception(" El parametro del rol {$rol} es incorrecto ", 1);
                  if ($value!='') {
                     if (is_numeric(array_search(strtolower($value), array_map( function ($v){return strtolower($v);}, $param)))) {
                        $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                        $temp = str_replace(":values", implode(',', @$param), $temp);
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'numeric':
                  if ($value!='') {
                     if ( !is_numeric( str_replace( ',','.', $value ) ) ) {
                        $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'regex':
                  if (@$param[0]=='') throw new Exception(" El parametro del rol {$rol} es incorrecto ", 1);
                  if ($value!='') {
                     if (!preg_match($param[0], $value)) {
                        $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'required':
                  if ($value==="" || $value===false || $value===null) {
                     $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                     $temp = str_replace(":data", $value, $temp);

                     $this->fails["messages"][$field][] = $temp;
                     $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                  }
                  break;
               case 'required_if':
                  # syntax: required_if:field1,value1,field2,value2,...
                  if (@$param[0]=='') throw new Exception(" El parametro del rol {$rol} es incorrecto ", 1);
                  if ((count(@$param)%2)!=0) throw new Exception(" Los valores del parametro del rol {$rol} deben ser de campo-valor. Ej. field1,value1,field2,value2,... ", 1);
                  $str = [];
                  foreach($param as $key => $v) {
                     if(($key%2)==0)
                        $d = $data[$v];
                     else
                        $str[] = "( '".trim($d)."' == '".trim($v)."' )";
                  }

                  $eval = null;
                  eval('$eval = '.join('||', $str).';');

                  if ( ($value==="" || $value===false || $value===null) && $eval ) {
                     $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                     $temp = str_replace(":other", @$param[0], $temp);
                     $temp = str_replace(":values", @$param[1], $temp);
                     $temp = str_replace(":data", $value, $temp);

                     $this->fails["messages"][$field][] = $temp;
                     $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                  }
                  break;
               case 'required_less':
                  # syntax: required_less:field1,value1,field2,value2,...
                  if (@$param[0]=='') throw new Exception(" El parametro del rol {$rol} es incorrecto ", 1);
                  if ((count(@$param)%2)!=0) throw new Exception(" Los valores del parametro del rol {$rol} deben ser de campo-valor. Ej. field1,value1,field2,value2,... ", 1);
                  $str = [];
                  foreach($param as $key => $v) {
                     if(($key%2)==0)
                        $d = $data[$v];
                     else
                        $str[] = "( '".trim($d)."' != '".trim($v)."' )";
                  }

                  $eval = null;
                  eval('$eval = '.join('||', $str).';');

                  if ( ($value==="" || $value===false || $value===null) && $eval ) {
                     $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                     $temp = str_replace(":other", @$param[0], $temp);
                     $temp = str_replace(":values", @$param[1], $temp);
                     $temp = str_replace(":data", $value, $temp);

                     $this->fails["messages"][$field][] = $temp;
                     $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                  }
                  break;
               case 'required_with':
                  if (@$param[0]=='') throw new Exception(" El parametro del rol {$rol} es incorrecto ", 1);
                  if (!is_numeric(array_search(strtolower($value), array_map( function ($v){return strtolower($v);}, $param)))) {
                     $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                     $temp = str_replace(":values", implode(',', @$param), $temp);
                     $temp = str_replace(":data", $value, $temp);

                     $this->fails["messages"][$field][] = $temp;
                     $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                  }
                  break;
               case 'required_without':
                  if (@$param[0]=='') throw new Exception(" El parametro del rol {$rol} es incorrecto ", 1);
                  if (is_numeric(array_search(strtolower($value), array_map( function ($v){return strtolower($v);}, $param)))) {
                     $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                     $temp = str_replace(":values", implode(',', @$param), $temp);
                     $temp = str_replace(":data", $value, $temp);

                     $this->fails["messages"][$field][] = $temp;
                     $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                  }
                  break;
               case 'same':
                  if (@$param[0]=='') throw new Exception(" El parametro del rol {$rol} es incorrecto ", 1);

                  $d = [$field => $value,];
                  $r = [$field => implode('|', $rules[@$param[0]]),];

                  $Validator = new Validator;
                  $v = $Validator->make($d,$r,$messages);

                  if (count($v->fails) || strtolower($value)!=strtolower($data[@$param[0]])) {
                     if (count($v->fails)) {
                        $this->fails["messages"][$field]   = $v->fails["messages"][$field];
                        $this->fails["failed"]  [$field]   = $v->fails["failed"]  [$field];
                     }else{
                        $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                        $temp = str_replace(":other", @$param[0], $temp);
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'size':
                  //    "numeric"            "file"            "string"          "array"
                  if (@$param[0]=='' || !is_numeric(@$param[0])) throw new Exception(" El parametro del rol {$rol} es incorrecto ", 1);
                  if ($value!='') {
                     $len = $value;
                     if (is_array($value)) {
                        $len = count($value);
                     }elseif (!is_numeric($value)) {
                        $len = strlen($value);
                     }

                     if (!count($param) || ($len) != (@$param[0])) {
                        if (is_array($value)) {
                           $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol]['array'])));
                        }elseif (!is_numeric($value)) {
                           $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol]['string'])));
                        }else{
                           $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol]['numeric'])));
                        }

                        $temp = str_replace(":size", @$param[0]?@$param[0]:0, $temp);
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'text':
                  if ($value!='') {
                     // ASCII lATIN1
                     // if ($value) {
                     //    $this->fails["messages"][$field][] = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                     //    $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     // }
                  }
                  break;
               case 'unique':break;
               case 'url':
                  if ($value!='') {
                     if (!filter_var($value, FILTER_VALIDATE_URL)) {
                        $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                        $temp = str_replace(":data", $value, $temp);

                        $this->fails["messages"][$field][] = $temp;
                        $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                     }
                  }
                  break;
               case 'sqlStatement':
                  if ($value!='') {
                     $strings = explode(' ',$value);
                     foreach($strings as $key => $string) {
                        if(in_array(strtolower($string), $this->sqlStatement)) {
                           $temp = str_replace(":attribute", $field, (@$messages[$rol] ? @$messages[$rol] : (@$messages[$field] ? @$messages[$field] : @$this->messages[$rol])));
                           $temp = str_replace(":values", strtoupper($string), $temp);
                           $temp = str_replace(":data", $value, $temp);

                           $this->fails["messages"][$field][] = $temp;
                           $this->fails["failed"]  [$field][] = $rules[$field][$key_rol];
                           break;
                        }
                     }
                  }
                  break;
               default:
                  $error = false;
                  $message = null;
                  if(@$this->roles_created[$rol] instanceof closure || gettype(@$this->roles_created[$rol])==='object') { // 'rol' => function();
                     $error = $this->roles_created[$rol]($value, $param, $data, $this);
                  }
                  elseif(@$this->roles_created[$rol][0] instanceof closure || gettype(@$this->roles_created[$rol][0])==='object') { // 'rol' => [function()];
                     $error = $this->roles_created[$rol][0]($value, $param, $data, $this);
                  }
                  elseif(is_string(@$this->roles_created[$rol][0]) && (@$this->roles_created[$rol][1] instanceof closure || gettype(@$this->roles_created[$rol][1])==='object')) { // 'rol' => ['message',function()];
                     $message = $this->roles_created[$rol][0];
                     $error = $this->roles_created[$rol][1]($value, $param, $data, $this);
                  }

                  if(is_array($error)) {
                     $temp_error = $error;
                     $error   = @$temp_error['error'];
                     if(@$temp_error['message'])
                        $message = @$temp_error['message'];
                  }
                  if($error) {
                     $temp_value = is_array($value) ? 'Array' : $value;
                     $message = $message ? $message : @$messages[$rol];
                     $temp = str_replace(":attribute", $field, $message);
                     $temp = str_replace(":values", implode(',', @$param), $temp);
                     $temp = str_replace(":data", $temp_value, $temp);

                     $this->fails["messages"][$field][] = $temp;
                     $this->fails["failed"]  [$field][] = $rol;
                  }

                  break;
            }
         }
      }

      return $this;
   }
616774
public function instance_form_validation(array $data, array $files) : array {

        $errors = parent::instance_form_validation($data, $files);
        $maxlength = $this->get_field()->get_configdata_property('maxlength');
        $elementname = $this->get_form_element_name();
        if (($maxlength > 0) && ($maxlength < \core_text::strlen($data[$elementname]))) {
            $errors[$elementname] = get_string('errormaxlength', 'customfield_text', $maxlength);
        }
        return $errors;
    }
1203984
protected function validate_use_validator( array $data, array $rules ) {
		if ( empty( $rules ) ) {
			return;
		}

		$validator = new Validator( $data, $rules );

		$validator->labels(
			$this->fields->pluck( 'name', 'id' )->all()
		);

		if ( $validator->fails() ) {
			foreach ( $rules as $key => $rule ) {
				$this->add_error( $key, $validator->errors( $key ) );
			}
		}
	}
508421
public function validateData(array $data, array $rules, array $messages)
    {
        if ($rules) {
            $this->customValidator->setData($data);
            $this->customValidator->setRules($rules);
            $this->customValidator->setCustomMessages($messages);

            //if the validator fails, kick back the errors
            if ($this->customValidator->fails()) {
                return implode('. ', $this->customValidator->messages()->all());
            }
        }

        return true;
    }
1020030
public function validate(Request $request, array $rules, array $messages = [])
    {
        foreach ($rules as $param => $options) {
            $value = $request->getParam($param);
            $this->data[$param] = $value;
            $isRule = $options instanceof V;

            try {
                if ($isRule) {
                    $options->assert($value);
                } else {
                    if (!isset($options['rules']) || !($options['rules'] instanceof V)) {
                        throw new InvalidArgumentException('Validation rules are missing');
                    }

                    $options['rules']->assert($value);
                }
            } catch (NestedValidationException $e) {
                $paramRules = $isRule ? $options->getRules() : $options['rules']->getRules();

                // Get the names of all rules used for this param
                $rulesNames = [];
                foreach ($paramRules as $rule) {
                    $rulesNames[] = lcfirst((new ReflectionClass($rule))->getShortName());
                }

                // If the 'message' key exists, set it as only message for this param
                if (!$isRule && isset($options['message']) && is_string($options['message'])) {
                    $this->errors[$param] = [$options['message']];
                    return $this;
                } else { // If the 'messages' key exists, override global messages
                    $params = [
                        $e->findMessages($rulesNames)
                    ];

                    // If default messages are defined
                    if (!empty($this->defaultMessages)) {
                        $params[] = $e->findMessages($this->defaultMessages);
                    }

                    // If global messages are defined
                    if (!empty($messages)) {
                        $params[] = $e->findMessages($messages);
                    }

                    // If individual messages are defined
                    if (!$isRule && isset($options['messages'])) {
                        $params[] = $e->findMessages($options['messages']);
                    }

                    $this->errors[$param] = array_values(array_filter(call_user_func_array('array_merge', $params)));
                }
            }
        }

        return $this;
    }
199138
public static function make(array $data, array $rules, array $userMessages = [])
    {
        self::$validatorFacade = new ValidatorFacade($userMessages);

        $data = self::prepareData($data);
        $rules = self::prepareRules($rules);

        foreach ($rules as $fieldName => $fieldRules) {
            $fieldName = trim($fieldName);
            $fieldRules = trim($fieldRules);

            if (!$fieldRules) {
                //no rules
                continue;
            }

            $groupedRules = explode('|', $fieldRules);

            foreach ($groupedRules as $concreteRule) {
                $ruleNameParam = explode(':', $concreteRule);
                $ruleName = $ruleNameParam[0];

                //for date/time validators
                if (count($ruleNameParam) >= 2) {
                    $ruleValue = implode(':', array_slice($ruleNameParam, 1));

                    //for other params
                } else {
                    $ruleValue = isset($ruleNameParam[1]) ? $ruleNameParam[1] : '';
                }

                self::$config[BaseRule::CONFIG_DATA] = $data;
                self::$config[BaseRule::CONFIG_FIELD_RULES] = $fieldRules;

                $ruleInstance = RulesFactory::createRule($ruleName, self::$config, [
                    $fieldName,                                        // The field name
                    isset($data[$fieldName]) ? $data[$fieldName] : '', // The provided value
                    $ruleValue,                                        // The rule's value
                ]);

                if (!$ruleInstance->isValid()) {
                    self::$validatorFacade->chooseErrorMessage($ruleInstance);
                }
            }
        }

        return self::$validatorFacade;
    }
564388
public static function validate($data, $rules)
	{
		$errors = array();

		foreach ($data as $k => $v)
		{
			if (array_key_exists($k, $rules))
			{
				// (Re)set rule variable
				$rule = null;

				if (is_callable($rules[$k]))
				{
					if ($error = call_user_func_array($rules[$k], [$data]))
					{
						$errors[] = $error;
					}
				}
				else if (strpos($rules[$k], '|'))
				{
					$rule = explode('|', $rules[$k]);
				}
				else
				{
					$rule = array($rules[$k]);
				}

				if (isset($rule))
				{
					foreach ($rule as $r)
					{
						if (method_exists(__CLASS__, $r))
						{
							if ($error = self::$r($k, $v))
							{
								$errors[] = $error;
							}
						}
					}
				}
			}
		}

		return (count($errors) > 0) ? $errors : true;
	}
628408
public static function make($data, array $rules, array $customMessages = [], array $attributes = [])
    {
        return new Validator($data, $rules, $customMessages, $attributes);
    }
302407
private function prepareRecord(array $data, array $rules, array $messages)
    {
        // Reset error bag
        $this->errors = new MessageBag;

        // Capture data
        $this->setDataset($data);
        $this->setRuleset($rules);
        $this->setMessageset($messages);

        // Fill model
        $this->fillModel();
    }
151998
protected function addIteratedValidationRules($attribute, $ruleSet = [], $messages = [])
    {
        foreach ($ruleSet as $field => $rules) {
            $rules = str_replace('{parent}', rtrim($attribute, '.'), $rules);
            $rules = str_replace('{index}.', $attribute, $rules);
            $rules = is_string($rules) ? explode('|', $rules) : $rules;

            //If it contains nested iterated items, recursively add validation rules for them too
            if (isset($rules['iterate'])) {
                $this->iterateNestedRuleSet($attribute.$field, $rules);
                unset($rules['iterate']);
            }

            $this->mergeRules($attribute.$field, $rules);
        }
        $this->addIteratedValidationMessages($attribute, $messages);
    }
934210
public function validate( $data, array $rules = [] )
	{
		$this->normalizeData( $data );
		$this->setRules( $rules );

		foreach( $this->rules as $attribute => $rules ) {
			foreach( $rules as $rule ) {
				$this->validateAttribute( $rule, $attribute );

				if( $this->shouldStopValidating( $attribute ))break;
			}
		}

		return $this->errors;
	}
334849
public function error($message, $data=null){
        is_object($data) && $data = (array)$data;
        $return = ['success' => false, 'message' => $message, 'data'=>$data];
        return $return;
    }
1259040
public function validateDataWithRules(array $data, array $validateRules, array $validateMessages = [], array $parametricConverter = [])
    {
        foreach ($validateRules as $key => $rules) {
            $value = array_key_exists($key, $data) ? $data[$key] : null;

            if (array_key_exists('nullable', $rules) && $rules['nullable'] && is_null($value)) {
                continue;
            }

            unset($rules['nullable']);

            $defaultParametricConverter = (method_exists($this, 'getParametricConverter') && is_array($this->getParametricConverter())) ? $this->getParametricConverter() : [];
            $parametricConverter = array_merge($defaultParametricConverter, $parametricConverter);
            $parameter = (array_key_exists($key, $parametricConverter)) ? $parametricConverter[$key] : $key;

            foreach ($rules as $ruleName => $ruleParameter) {
                if ($ruleName === 'callback') {
                    if (!is_callable($ruleParameter)) {
                        throw new BadMethodCallException('The reference of rule named `callback` must be a valid callable. You provided ' . $this->getValueDescription($ruleParameter) . '.');
                    }

                    call_user_func($ruleParameter, $value, InvalidRequestException::class);
                } else {
                    $method = 'check'.ucfirst(Helper::camelCase($ruleName));

                    if (!method_exists($this, $method)) {
                        throw new BadMethodCallException('Call to undefined the ' .get_class($this). '::' .$method. '() validator that associated with the `' .$ruleName. '` rule');
                    }

                    if (!$this->$method($value, $ruleParameter)) {
                        $message = isset($validateMessages[$key][$ruleName]) ? $validateMessages[$key][$ruleName] : null;

                        throw new InvalidRequestException($this->formatMessage($parameter, $ruleName, $ruleParameter, $message));
                    }
                }
            }
        }
    }
598269
public function applyRules(array $rules = [], array $data = []): array
    {
        $data  = $data ?: $this->_data;
        $rules = $rules ?: $this->_rules;
        // save clean data
        $filtered = [];

        foreach ($rules as $rule) {
            if (!isset($rule[0], $rule[1])) {
                continue;
            }

            if (!$fields = $rule[0]) {
                continue;
            }

            $fields = \is_string($fields) ? Filters::explode($fields) : (array)$fields;

            foreach ($fields as $field) {
                if (!isset($data[$field])) {
                    $filtered[$field] = $rule['default'] ?? null;
                } else {
                    $filtered[$field] = $this->valueFiltering($data[$field], $rule[1]);
                }
            }
        }

        return $filtered;
    }