@param string $field
@param array  $data
@param array  $rules

@return bool|mixed
557017
private function validateField($field, $data, $rules) {
		foreach ($rules as $rule) {
			list($m, $ops, $msg) = $rule;
			$valid_m = 'v_' . $m;
			if (method_exists($this, $valid_m)) {
				if ($msg) {
					$msg = preg_replace('#\{\d+?\}#', '%s', $msg);
				}
				$valid = $this->$valid_m ($field, $ops, $data, $msg);
			} else {
				return _t('notsupportmethod@validator', $field, $m);
			}
			if ($valid !== true) {
				return $valid;
			}
		}

		return true;
	}
1091187
public function validate(array $data, $rules = null, $custom = false)
    {
        if (!$custom) {
            $rules = $this->rules($rules);
        }

        return $this->validator->make($data, $rules);
    }
491903
protected function _dataPreparation($key, $data, array $rulesList)
    {
        foreach ($rulesList as $ruleKey => $function) {

            switch (true) {
                case is_null($key):
                    $data = $this->_prepareWholeData($ruleKey, $data, $function);
                    break;

                case preg_match($ruleKey, $key) && !is_null($key):
                    $data = $this->_callUserFunction($function, $key, $data, null);
                    break;

                default:
                    break;
            }
        }

        return $data;
    }
301256
public function addRules(string $field, array $ruleSet): Validator
	{
		$this->ruleSets = array_merge_recursive($this->ruleSets, $this->expandFields([$field => $ruleSet]));

		return $this;
	}
313148
public function getRuleValidator($field, $rule)
    {
        return isset($this->ruleValidators[$field][$rule]) ? $this->ruleValidators[$field][$rule] : null;
    }
564388
public static function validate($data, $rules)
	{
		$errors = array();

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

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

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

		return (count($errors) > 0) ? $errors : true;
	}
1183735
public static function conditionIn($field, array $values, $required = true)
    {
        return self::buildConditionIn($field, $values, $required, false);
    }
1340335
public function mapFieldRules(string $field, array $rules)
    {
        foreach ($rules as $rule) {
            //rule must be an array
            $rule = (array) $rule;

            //First element is the name of the rule
            $name = \array_shift($rule);

            //find a custom message, if any
            $message = null;
            if (isset($rule['message'])) {
                $message = $rule['message'];
                unset($rule['message']);
            }

            //Add the field and additional parameters to the rule
            $this->rule($name, $field, ...$rule);

            if (!empty($message)) {
                $this->message($message);
            }
        }
    }
308350
public function add_rule($field, $rule) {

		if(!$rule instanceof \HybridLogic\Validation\Rule) return $this;

		if(!isset($this->labels[$field])) {
			$this->set_label($field, $this->humanize_field_name($field));
		}

		if(!isset($this->rules[$field])) $this->rules[$field] = array();
		$this->rules[$field][] = $rule;

		return $this;

	}
1169667
public function rule($rule, $fields, ...$params)
    {
        if (\is_callable($rule)
            && !(\is_string($rule) && $this->hasValidator($rule))
        ) {
            $name = $this->getUniqueRuleName($fields);
            $message = $params[0] ?? null;
            $this->addInstanceRule($name, $rule, $message);
            $rule = $name;
        }

        $errors = $this->getRules();
        if (!isset($errors[$rule])) {
            $ruleMethod = 'validate' . \ucfirst($rule);
            if (!\method_exists($this, $ruleMethod)) {
                throw new \InvalidArgumentException("Rule '" . $rule . "' has not been registered with " . __CLASS__ . "::addRule().");
            }
        }

        // Ensure rule has an accompanying message
        $messages = $this->getRuleMessages();
        $message = $messages[$rule] ?? self::ERROR_DEFAULT;

        // Ensure message contains field label
        if (\strpos($message, '{field}') === false) {
            $message = '{field} ' . $message;
        }

        $this->_validations[] = [
            'rule' => $rule,
            'fields' => (array) $fields,
            'params' => (array) $params,
            'message' => '{field} ' . $message,
            'skip' => self::SKIP_CONTINUE,
        ];

        return $this;
    }
286230
public function addError($field, $validation, $data)
    {
        if (!isset($this->errors[$field])) {
            $this->errors[$field] = array();
        }

        $this->errors[$field][$validation] = $data;
    }
338573
public function validator($field, array $data)
    {
        $value = isset($data[$field]) ? $data[$field] : null;
        if ($value === '' || $value === null) {
            return $this->allowEmpty ? true : $this->message('{fieldName}不是整数！', [
                '{fieldName}' => $this->getName($field),
            ], 'emptyMsg');
        }

        if ($this->min !== null && $this->min > $value) {
            return $this->message('{fieldName}不能小于{min}！', [
                '{fieldName}' => $this->getName($field),
                '{min}' => $this->min,
            ], 'tooSmall');
        }

        if ($this->max !== null && $this->max < $value) {
            return $this->message('{fieldName}不能大于{max}！', [
                '{fieldName}' => $this->getName($field),
                '{max}' => $this->max,
            ], 'tooBig');
        }

        if (!preg_match($this->intOnly ? $this->intPattern : $this->numberPattern, $value)) {
            return $this->message('{fieldName}不是' . ($this->intOnly ? '整数' : '数字') . '！', [
                '{fieldName}' => $this->getName($field),
            ]);
        }

        return true;
    }
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 ) );
			}
		}
	}
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;
    }
1345882
private function processRuleset($field, array $set)
    {
        $rules = [];

        foreach ($set as $rule)
        {
            // If this rule is an array skip it because it's going to be a relationship
            if (is_array($rule)) continue;

            list($type, $parameters) = $this->getRuleTypeAndParameters($rule);
            $parameters = $this->parseRuleParameters($field, $parameters);
            $parameters = $this->parseUniqueRule($field, $parameters, $type);

            // Rebuild rule
            $rules[] = $this->rebuildRule($type, $parameters);
        }

        return $rules;
    }
36339
public function getUserByField($field, $data)
    {
        $user = new User();
        $userVarArray = get_object_vars($user);
        $arrayKeys = array_keys($userVarArray);
        $userData = $this->userStorage->getUserByField($field, $data);
        if (empty($userData)) {
            return $user;
        }
        foreach ($arrayKeys as $key) {
            $user->{$key} = $userData->$key;
        }
        return $user;
    }
100968
public function validator($field, array $data)
    {
        $value = isset($data[$field]) ? $data[$field] : null;
        if ($value === '' || $value === null) {
            return $this->allowEmpty ? true : $this->message('{fieldName}不能为空！', [
                '{fieldName}' => $this->getName($field),
            ], 'emptyMsg');
        }

        if (!is_callable($this->checkBy)) {
            throw new ParamsException('checkBy', 'not callable');
        }

        $len = call_user_func($this->checkBy, $value);
        if ($this->min !== null && $this->min > $len) {
            return $this->message('{fieldName}长度不能小于{min}！', [
                '{fieldName}' => $this->getName($field),
                '{min}' => $this->min,
            ], 'tooSmall');
        }

        if ($this->max !== null && $this->max < $len) {
            return $this->message('{fieldName}长度不能大于{max}！', [
                '{fieldName}' => $this->getName($field),
                '{max}' => $this->max,
            ], 'tooBig');
        }

        if ($this->equal !== null && $this->equal != $len) {
            return $this->message('{fieldName}长度不等于{equal}！', [
                '{fieldName}' => $this->getName($field),
                '{equal}' => $this->equal,
            ], 'notEqual');
        }

        return true;
    }