Make validation.

@param array $data         user request data
@param array $rules        validation rules
@param array $userMessages custom error messages

@return ValidatorFacade
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;
    }
376429
protected function executeValidation(array $data)
    {
        if ($method = array_get($this->scenario, 'on')) {
            call_user_func_array([$this, $method], $this->scenario['arguments']);
        }

        $rules = $this->getBoundRules();

        $messages = $this->getMessages();

        $customAttributes = $this->getCustomAttributes();

        $validator = $this->factory->make($data, $rules, $messages, $customAttributes);

        return $validator->errors();
    }
737538
public final function validate(array $data = null, array $rules = null) {
		if ($data === null && isset($this->_formData)) {
			$data = $this->_formData;
		}
		if (empty($data)) {
			throw new ValidateException(['error' => 'data is empty']);
		}
		if ($rules) {
			$this->rules    = [];
			$this->rulesIdx = [];
			$this->ruleKeys = [];
			foreach ($rules as $field => $rule) {
				$this->addRule($field, $rule);
			}
		}

		return $this->validateNewData($data);
	}
952079
public function validate(Request $request, array $rules, array $messages = [], array $attributes = [])
    {
        $this->getValidationFactory()
            ->make($request->all(), $rules, $messages, $attributes)
            ->validate();

        return $this->extractInputFromRules($request, $rules);
    }
38401
public static function create(array $rules, array $data = null, bool $validateAndThrowException = true): Validator
    {
        $validator = new static($rules, $data);

        if ($validateAndThrowException) {
            if (!$validator->isAllValid()) {
                $exception = new InvalidDataException('Validator exception');
                $exception->setValidator($validator);
                throw $exception;
            }
        }

        return $validator;
    }
595440
private function checkFields(array $data)
    {
        $ruleset = $this->validationRules();
        $mismatch = array_diff_key($data, $ruleset);
        $fields = array_keys($mismatch);

        foreach ($fields as $field) {
            $this->errors[] = array(
                'field' => $field,
                'value' => $data[$field],
                'rule' => 'mismatch',
                'param' => null,
            );
        }

        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;
   }
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();
    }
906252
public function validate(array $params, array $rules, array $messages = [])
    {
        $validator = app(Validator::class)->make($params, $rules, $messages);

        if ($validator->fails()) {
            throw new ValidationException(
                $validator, new JsonResponse($validator->errors()->getMessages(), 422)
            );
        }
    }
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 ) );
			}
		}
	}
231533
public function validator(User $user, array $data)
    {
        return Validator::make($data, [
            'name'                  => 'required|max:255|unique:users,name,'.$user->id,
            'email'                 => 'required|email|max:255|unique:users,email,'.$user->id,
            'password'              => 'confirmed|min:6',
            'birthday_at'           => 'date|before:now',
            'gender'                => 'in:male,female',
            'locale'                => 'required|size:2',
            'homepage'              => 'url|max:100',
            'skype'                 => 'min:6|max:32',
            'facebook'              => 'url|max:50',
            'twitter'               => 'url|max:50',
            'main_character'        => 'min:2|max:20',
            'main_guild'            => 'max:50',
            'favorite_race'         => 'max:20',
            'favorite_class'        => 'max:20',
            'favorite_spec'         => 'max:20',
            'favorite_instance'     => 'max:50',
            'favorite_battleground' => 'max:50',
        ]);
    }
238970
protected function validate(array &$data)
    {
        $messages = [];
        if (!empty($data['errors']) && !empty($data['activity']) && !empty($data['requests'])) {
            array_push($messages, ['warning', trans('It is recommended to periodically clean system logs.')]);
        }
        $data = array_merge($data, ['messages' => $messages]);
        return $data;
    }
111961
protected function validate($data, $rules=false)
    {
        if(!$rules)
        {
            $modelName = $this->modelFullName;
            $rules = $modelName::$rules;
        }
        $validator = \Validator::make($data, $rules);
        if($validator->fails()) throw new ValidationException($validator);
        return true;
    }
149402
public function validateRequestOrFail($request, array $rules, $messages = [], $customAttributes = [])
    {
        $validator = $this->getValidationFactory()->make($request->all(), $rules, $messages, $customAttributes);

        if ($validator->fails()) {
            throw new HttpException(400, json_encode($validator->errors()->getMessages()));
        }
    }
334273
public function addValidationMessage($rule, $message)
    {
        if (($pos = strpos($rule, ':')) !== false) {
            $rule = substr($rule, 0, $pos);
        }

        $this->validationMessages[$rule] = $message;

        return $this;
    }
1367215
public function validation($data, $files) {
        global $OUTPUT;
        $errors = parent::validation($data, $files);
        $addcourse = $this->_customdata['addcourse'];

        if (!$addcourse &&
                isset($this->_customdata['criteria']->required_param) &&
                !isset($this->_customdata['criteria']->self_validation)) {

            $required = $this->_customdata['criteria']->required_param;
            $pattern1 = '/^' . $required . '_(\d+)$/';
            $pattern2 = '/^' . $required . '_(\w+)$/';

            $ok = false;
            foreach ($data as $key => $value) {
                if ((preg_match($pattern1, $key) || preg_match($pattern2, $key)) && !($value === 0 || $value == '0')) {
                    $ok = true;
                }
            }

            $warning = $this->_form->createElement('html',
                    $OUTPUT->notification(get_string('error:parameter', 'badges'), 'notifyproblem'), 'submissionerror');

            if (!$ok) {
                $errors['formerrors'] = 'Error';
                $this->_form->insertElementBefore($warning, 'first_header');
            }
        }
        return $errors;
    }
561414
protected function makeValidator(array $rules, array $attributes)
	{
		$validator = $this->factory->make($attributes, $rules);
		$this->prepareValidator($this->validator);
		return $validator;
	}