url

@param \MadeSimple\Validator\Validator $validator
@param array $data
@param string $pattern
@param string $rule
424959
public static function url(Validator $validator, $data, $pattern, $rule)
    {
        foreach (Validator::getValues($data, $pattern) as $attribute => $value) {
            if (null === $value || empty($value)) {
                continue;
            }
            if (false !== filter_var($value, FILTER_VALIDATE_URL)) {
                continue;
            }

            $validator->addError($attribute, $rule);
        }
    }
663313
public function run(array $data, $check_fields = false, $rules_delimiter='|', $parameters_delimiters=',')
    {
        $data = $this->filter($data, $this->filter_rules(), $rules_delimiter, $parameters_delimiters);

        $validated = $this->validate(
            $data, $this->validation_rules(),
            $rules_delimiter, $parameters_delimiters
        );

        if ($check_fields === true) {
            $this->check_fields($data);
        }

        if ($validated !== true) {
            return false;
        }

        return $data;
    }
1243978
public static function alpha(Validator $validator, $data, $pattern, $rule)
    {
        foreach (Validator::getValues($data, $pattern) as $attribute => $value) {
            if (null === $value || empty($value)) {
                continue;
            }
            if (preg_match('/^([a-zÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖßÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ])+$/i', $value) === 1) {
                continue;
            }

            $validator->addError($attribute, $rule);
        }
    }
1030212
public function validateData(Request $request, array $data, array $rules, array $messages = [], array $customAttributes = [])
    {
        $validator = $this->getValidationFactory()->make($data, $rules, $messages, $customAttributes);

        if ($validator->fails()) {
            $this->throwValidationException($request, $validator);
        }
    }
575684
private function __applyValidationRules($data)
    {
        $rule = $this->get('validator');

        return ($rule ? General::validateString($data, $rule) : true);
    }
24988
public function execute()
    {
        $to_compare_with = func_get_arg(0);
        $mode = func_num_args() == 1 ? '=' : func_get_arg(1);
        
        $modes = [
            '=',
            '>',
            '<',
            '>=',
            '<='
        ];
        
        if (! in_array($mode, $modes)) {
            Throw new ValidatorException(sprintf('Parameter "%s" not allowed', $mode), 1001);
        }
        
        switch ($mode) {
            case '=':
                $result = $this->value == $to_compare_with;
                break;
            
            case '>':
                $result = $this->value > $to_compare_with;
                break;
            
            case '<':
                $result = $this->value < $to_compare_with;
                break;
            
            case '>=':
                $result = $this->value >= $to_compare_with;
                break;
            
            case '<=':
                $result = $this->value <= $to_compare_with;
                break;
        }
        
        if (! $result) {
            $this->msg = [
                'validator.rule.compare',
                [
                    $this->value,
                    $to_compare_with,
                    $mode
                ]
            ];
        }
    }
692772
protected function validate(array $data, array $rules)
    {
        $validator = $this->validator->make($data, $rules);
        if ($validator->fails()) {
            throw new ValidationException($validator);
        }
        return $this;
    }
699514
private function parseRule($rule)
	{
		if (!is_array($rule) || (count($rule) < 2)) {
			throw new ValidatorException('Invalid declaration of validation rule');
		}

		is_array($rule[0]) || $rule[0] = [$rule[0]];

		if (!is_string($rule[1])) {
			throw new ValidatorException('Validator name: Expected string');
		}

		if (isset($rule[2])) {
			if(!is_array($rule[2])) {
				throw new ValidatorException('Validator options: Expected array');
			}
		} else {
			$rule[2] = [];
		}
		$rule[2] = new ArrayWrapper($rule[2]);

		return $rule;
	}
836055
public function getValidationMessage($attribute, $rule, $data = [], $type = null)
    {
        $path = Str::snake($rule);
        if ($type !== null) {
            $path .= '.' . $type;
        }

        if ($this->translator->has('validation.custom.' . $attribute . '.' . $path)) {
            $path = 'custom.' . $attribute . '.' . $path;
        }

        $niceName = $this->getValidationAttribute($attribute);

        return $this->translator->get('validation.' . $path, $data + ['attribute' => $niceName]);
    }
624667
public function execute()
    {
        $result = filter_var($this->value, FILTER_VALIDATE_URL);
        
        if ($result === false) {
            $this->msg = 'validator.rule.url';
        }
    }
1080476
public static function greaterThan(Validator $validator, $data, $pattern, $rule, $parameters)
    {
        $lowerBound = Validator::getValue($data, $parameters[0]);
        if (null === $lowerBound) {
            return;
        }
        foreach (Validator::getValues($data, $pattern) as $attribute => $value) {
            if (null === $value || empty($value)) {
                continue;
            }
            if ($value > $lowerBound) {
                continue;
            }
            $validator->addError($attribute, $rule, [':value' => $value]);
        }
    }
184514
public function validate($data, array $rules, $context = null): ValidatorInterface
    {
        return new Validator($data, $rules, $context, $this);
    }
1367247
public static function required(Validator $validator, $data, $pattern, $rule)
    {
        // Check pattern is present
        if (!ArrDots::has($data, $pattern, $validator::WILD)) {
            $validator->addError($pattern, $rule);
        }

        // Check value is not null
        foreach (Validator::getValues($data, $pattern) as $attribute => $value) {
            if (null !== $value) {
                continue;
            }

            $validator->addError($attribute, $rule);
        }
    }
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;
   }
134441
protected function validate($attribute, $rule)
	{
		list($rule, $parameters) = $this->parseRule($rule);

		if ($rule == '') return;

		// We will get the value for the given attribute from the array of data and then
		// verify that the attribute is indeed validatable. Unless the rule implies
		// that the attribute is required, rules are not run for missing values.
		$value = $this->getValue($attribute);

		$validatable = $this->isValidatable($rule, $attribute, $value);

		$method = "validate{$rule}";

		if ($validatable && ! $this->$method($attribute, $value, $parameters, $this))
		{
			$this->addFailure($attribute, $rule, $parameters);
		}
	}
559270
public static function makeUrl( array $data, RuleCollection $collection, Url $url = null ): string
	{
		$path = [];
		$get = [];
		$close = true;
		$protocol = "";
		$host = "";
		$port = 80;

		/** @var RuleInterface $item */
		foreach( $collection as $item )
		{
			if( $item instanceof RuleHost )
			{
				$protocol = $item->getProtocol();
				$host = $item->getHost();
				$port = $item->getPort();
			}

			else if( $item instanceof RuleStatic )
			{
				$path[] = $item->getSegment();
				$close = ! $item->isOpen();
			}

			else if( $item instanceof RuleSegment )
			{
				$name = $item->getName();
				if( ! isset($data[$name]) || is_array($data[$name]) && ! count($data[$name]) )
				{
					if( $item->isRequired() )
					{
						throw new \InvalidArgumentException("Insufficient data");
					}
				}

				else if( $item->isSingle() )
				{
					$path[] = $item->getPrefix() . ( is_array($data[$name]) ? current($data[$name]) : $data[$name] ) . $item->getSuffix();
				}

				else
				{
					$values = is_array($data[$name]) ? $data[$name] : [$data[$name]];
					foreach($values as $segment)
					{
						$path[] = $item->getPrefix() . $segment . $item->getSuffix();
					}
				}
			}
			else if( $item instanceof RuleGet )
			{
				$name = $item->getName();
				if( !isset($data[$name]) || ! $item->match($data[$name]))
				{
					if( $item->isRequired() )
					{
						throw new \InvalidArgumentException("Insufficient data");
					}
				}
				else
				{
					$get[$item->getQueryName()] = $data[$name];
				}
			}
		}

		// create path

		if( count($path) )
		{
			$path = "/" . implode("/", $path);
			if( $close )
			{
				$path .= "/";
			}
		}
		else
		{
			$path = "/";
		}

		if( count($get) )
		{
			$path .= "?" . http_build_query($get);
		}

		// create host

		if( ! strlen($host) )
		{
			if( ! is_null($url) )
			{
				$protocol = $url->getHost();
			}
			else if( defined("APP_HOST") )
			{
				$protocol = APP_HOST;
			}
			else if( App::getInstance()->loadIs("Url") )
			{
				$protocol = App::Url()->getHost();
			}
			else
			{
				return $path;
			}
		}

		// create protocol

		if( ! strlen($protocol) )
		{
			if( ! is_null($url) )
			{
				$protocol = $url->getProtocol();
			}
			else if( defined("BASE_PROTOCOL") )
			{
				$protocol = BASE_PROTOCOL;
			}
			else
			{
				$protocol = "http";
			}
		}

		// add port

		if( $port !== 80 )
		{
			$host .= ":" . $port;
		}

		return $protocol . "://" . $host . $path;
	}
956123
protected function requireIf($value, $rule, $data)
    {
        list($field, $val)=explode(',', $rule);
        if ($this->getDataValue($data, $field) == $val) {
            return !empty($value);
        } else {
            return true;
        }
    }