@param array|\ArrayAccess $data
@param array              $rules
@param null               $context

@return ValidatorInterface
184514
public function validate($data, array $rules, $context = null): ValidatorInterface
    {
        return new Validator($data, $rules, $context, $this);
    }
364722
private function evaluateRequestParams($data, $ruleModel)
    {
        foreach ($data as $key => $value) {
            if ($key !== 'form_key' && $key !== 'key' && $key !== 'active_tab') {
                if ($key == 'condition') {
                    if (is_array($value)) {
                        unset($value['__empty']);
                    }
                    $ruleModel->setData('conditions', $value);
                } else {
                    $ruleModel->setData($key, $value);
                }
            }
        }

        return $ruleModel;
    }
90205
public static function callRuleAlgorithm(
        ContextInterface $context,
        array $rulesData,
        LoggerInterface $logger = null
    ): array {
        return static::callAlgorithm(
            static::getCallable($rulesData),
            $context,
            static::getTargets($rulesData),
            static::getRules($rulesData),
            $logger
        );
    }
913075
public static function validator(RuleInterface $rule, ContainerInterface $container = null): ValidatorInterface
    {
        $validator = new static($rule, $container);

        return $validator;
    }
787856
protected function getValidatorInstance($rules, $data, $model=null)
    {
        $factory = $this->container->make('Illuminate\Validation\Factory');

        if (method_exists($this, 'validatorInstance'))
        {
            return $this->container->call(
                [$this, 'validatorInstance'],
                compact('factory')
            );
        }

        return $factory->make(
            $data, $rules, $this->customMessages(), $this->customAttributes()
        );
    }
36493
public function make($data, $rules)
    {
        $result = app('validator')->make($data, $rules);
        if ($result->fails()) {
            $this->errors = $result->messages()->toArray();
            return false;
        }
        $this->reset();
        return true;
    }
692772
protected function validate(array $data, array $rules)
    {
        $validator = $this->validator->make($data, $rules);
        if ($validator->fails()) {
            throw new ValidationException($validator);
        }
        return $this;
    }
544553
public function process(array $rules, array $data) {
        
        // If conditionning
        $this->rules[] = new Rule(
            'if_boolean', 
            'if:(\w+)', 
            '<?php if (isset($this->data[\'$1\']) && $this->data[\'$1\']): ?>'
        );
        $this->rules[] = new Rule(
        		'if_condition',
        		'if:(\w+)([!<>=]+)(\w+)',
        		'<?php if (isset($this->data[\'$1\'])){$base = $this->data[\'$1\'];}else{$base = \'$1\';};
        		if (isset($this->data[\'$3\'])){$value = $this->data[\'$3\'];}else{$value = \'$3\';}?>
        		<?php if ($base $2 $value): ?>'
        );
        $this->rules[] = new Rule(
            'ifnot', 
            'ifnot:(\w+)', 
            '<?php if (!isset($this->data[\'$1\']) || !$this->data[\'$1\']): ?>'
        );
        $this->rules[] = new Rule(
            'else', 
            'else', 
            '<?php else: ?>'
        );
        $this->rules[] = new Rule(
            'elseif_boolean', 
            'else:(\w+)', 
            '<?php elseif (isset($this->data[\'$1\']) && $this->data[\'$1\']): ?>'
        );
        $this->rules[] = new Rule(
            'elseif_condition', 
            'else:(\w+)([!<>=]+)(\w+)', 
            '<?php elseif (((isset($this->data[\'$1\']) && isset($this->data[\'$3\'])) && $this->data[\'$1\'] $2 $this->data[\'$3\']) ||
        		((isset($this->data[\'$1\']) && !isset($this->data[\'$3\'])) && $this->data[\'$1\'] $2 \'$3\') ||
        		((!isset($this->data[\'$1\']) && isset($this->data[\'$3\'])) && \'$1\' $2 $this->data[\'$3\']) ||
        		((!isset($this->data[\'$1\']) && !isset($this->data[\'$3\'])) && \'$1\' $2 \'$3\')): ?>'
        );
        $this->rules[] = new Rule(
            'endif', 
            'endif', 
            '<?php endif; ?>'
        );
        
        // Loops
        $this->rules[] = new Rule(
            'loop', 
            'loop:(\w+)', 
            '<?php foreach ($this->data[\'$1\'] as $element): $this->wrap($element); ?>'
        );
        $this->rules[] = new Rule(
            'endloop', 
            'endloop', 
            '<?php $this->unwrap(); endforeach; ?>'
        );
        
        // Importing
        $this->rules[] = new Rule(
            'import_view', 
            'import:(([^\/\s]+\/)?(.*))', 
            '<?php echo $this->importFile(\'$1\'); ?>'
        );
        
        // Clean variables
        $this->rules[] = new Rule(
            'escape_var', 
            'escape:(\w+)', 
            '<?php $this->showVariable(\'$1\', true); ?>'
        );
        
        // Custom rules
        $this->rules = array_merge($this->rules, $rules);
        
        // Variables
        $this->rules[] = new Rule(
            'variable', 
            '(\w+)', 
            '<?php $this->showVariable(\'$1\'); ?>'
        );
        
        // Arrays
        $this->rules[] = new Rule(
        		'variable_array',
        		'(\w+)\[(\w+)\]',
        		'<?php echo (isset($this->data[\'$1\'][\'$2\'])) ? $this->data[\'$1\'][\'$2\'] : "&#123;$1[$2]&#125"; ?>'
        );
        
        $this->rules[] = new Rule(
        		'variable_array_escape',
        		'escape:(\w+)\[(\w+)\]',
        		'<?php echo htmlentities($this->showVariable(\'$1\')[\'$2\']); ?>'
        );
        
        $this->data = $data;
        $this->stack = array();
        
        foreach ($this->rules as $rule) {
            $this->template = preg_replace('/\{' . $rule->rule() . '\}/', $rule->replacement(), $this->template);
        }
        
        $this->template = '?>' . $this->template;
        
        ob_start();
        eval($this->template);
        return ob_get_clean();
    }
892149
public function setRules(array $rules)
    {
        $this->validators = [];
        foreach ($rules as $rule) {
            if (is_array($rule[0]) && is_string($rule[1])) {
                continue;
            }
            throw new InvalidArgumentException('Bad validation rule');
        }
        $this->rules = $rules;

        return $this;
    }
476810
public function validate(array $data, array $rules, array $messages = [], array $customAttributes = [])
    {
        return $this->make($data, $rules, $messages, $customAttributes)->validate();
    }
1274152
public function addRules(array $rules) : ValidatorInterface
    {
        if (!is_array($rules) || empty($rules)) {
            throw new ValidatorException(sprintf('Validator::addRules() expect array of rules, %s given.', \gettype($rules)));
        }

        foreach ($rules as $field => $rule) {
            $this->addRule($field, $rule);
        }

        return $this;
    }
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());
        }
    }
932820
public static function requiredIf(Validator $validator, $data, $pattern, $rule, $parameters)
    {
        $field  = $parameters[0];
        $values = array_slice($parameters, 1);
        $isWild  = strpos($field, $validator::WILD) !== false;
        $overlap = Str::overlapLeft($field, $pattern);

        // If pattern is not present
        if (!ArrDots::has($data, $pattern, $validator::WILD)) {
            foreach (Validator::getValues($data, $field) as $fieldAttribute => $fieldValue) {
                if (null === $fieldValue || !in_array($fieldValue, $values)) {
                    continue;
                }

                $attribute = $isWild ? Str::overlapLeftMerge($overlap, $fieldAttribute, $pattern) : $pattern;
                $validator->addError($attribute, $rule, [':field' => $fieldAttribute, '%value' => implode(',', $values)]);
            }
            return;
        }

        // Check value is not null
        foreach (Validator::getValues($data, $pattern) as $attribute => $value) {
            $fieldAttribute = $isWild ? Str::overlapLeftMerge($overlap, $attribute, $field) : $field;
            $fieldValue     = ArrDots::get($data, $fieldAttribute);

            if ($fieldValue === null || !in_array($fieldValue, $values)) {
                continue;
            }

            if (null !== $value) {
                continue;
            }

            $validator->addError($attribute, $rule, [':field' => $fieldAttribute, '%value' => implode(',', $values)]);
        }
    }
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));
                    }
                }
            }
        }
    }
1027904
public function validate($all = false, $data = null, $rules = null)
	{
		if (null === $data)
		{
			$data = $this->data;
		}
		if (null === $rules)
		{
			$rules = $this->rule;
		}
		$this->result = array ();
		foreach ($rules as $rule)
		{
			// 规则合法性判断
			if (isset($rule['name']))
			{
				if (empty($rule['type']))
				{ // 无类型就不需要验证
					continue;
				}
				if (! isset($rule['msg']))
				{
					$rule['msg'] = false;
				}
			}
			else
			{
				if (count($rule) < 3)
				{
					throw new Exception(Lang::get('VAL_ARGS_LESS'));
					break;
				}
				$t = $rule;
				$rule = array ();
				// 直接传值处理
				$rule['name'] = $t[0];
				$rule['msg'] = $t[1];
				$rule['type'] = $t[2];
			}
			// 同名参数失败一次就不继续验证
			if (isset($this->result[$rule['name']]))
			{
				continue;
			}
			// 验证类型支持字符串方式
			if (! is_array($rule['type']))
			{
				$rule['type'] = explode(',', $rule['type']);
			}
			foreach ($rule['type'] as $k => $v)
			{
				// 验证方法传值处理
				if (is_numeric($k))
				{
					$type = $v;
					$args = array ($type);
				}
				else
				{
					$type = $k;
					$args = array_merge(array ($type), $v);
				}
				// 规则验证类型为是否存在
				if ('required' === $type)
				{
					$result = $this->required($rule['name'], $data);
				}
				else if ($this->required($rule['name'], $data))
				{
					// 值
					array_unshift($args, $data[$rule['name']]);
					// 调用验证方法
					$result = call_user_func_array(array ('self','check'), $args);
				}
				else
				{
					// 值不存在
					$result = false;
				}
				// 判断验证失败
				if (! $result)
				{
					if ($all)
					{
						$this->result[$rule['name']] = array ('name' => $rule['name'],'msg' => $rule['msg']);
					}
					else
					{
						$this->result = array ('name' => $rule['name'],'msg' => $rule['msg']);
						return $this->result;
					}
					break;
				}
			}
		}
		return $this->result;
	}
555043
public function validateContext($data, $rules)
	{
		// Start off with a valid status.
		$status = 'valid';

		// We only need to validate context if context rules are given.
		if(array_key_exists('context', $rules))
		{
			foreach($rules['context'] as $rule)
			{
				switch($rule)
				{
					case 'unique_email':
						$userPayload = $this->service['user']->get([['field' => 'email', 'value' => $data['email'], 'operator' => '=', 'or' => false]]);

						if($userPayload->getStatus() == 'found')
						{
							if(in_array($data['email'], $userPayload->getData()->pluck('email')->toArray()))
							{
								$status = $rule;
							}
						}
					break;

					case 'unique_username':
						$userPayload = $this->service['user']->get([['field' => 'username', 'value' => $data['username'], 'operator' => '=', 'or' => false]]);
						
						if($userPayload->getStatus() == 'found')
						{
							if(in_array($data['username'], $userPayload->getData()->pluck('username')->toArray()))
							{
								$status = $rule;
							}
						}
					break;

					default:
					break;
				}
			}
		}

		// @todo: check if we need to unset this.
		// Remove context rules as they're no longer needed.
		unset($rules['context']);

		return new Payload($data, $status);
	}
479500
public static function containsOnly(Validator $validator, $data, $pattern, $rule, $parameters)
    {
        foreach (Validator::getValues($data, $pattern) as $attribute => $value) {
            if (null === $value || empty($value)) {
                continue;
            }
            if (count($value) == count(array_intersect($value, $parameters))) {
                continue;
            }

            $validator->addError($attribute, $rule, [':values' => implode(', ', $parameters)]);
        }
    }