验证某个字段有值的情况下必须
@access protected

@param mixed $value 字段值
@param mixed $rule  验证规则
@param array $data  数据

@return bool
973655
protected function requireWith($value, $rule, $data)
    {
        $val = $this->getDataValue($data, $rule);
        if (!empty($val))
        {
            return !empty($value) || '0' == $value;
        }
        else
        {
            return true;
        }
    }
346728
public function check($value, IValidationData $data = null) {
        if (is_string($value)) {
            return filter_var($value, FILTER_VALIDATE_EMAIL) !== false;
        }
        return false;
    }
1068263
protected function maxValidate($value, $rule)
    {
        if (is_array($value)) {
            $length = count($value);
        }else {
            $length = mb_strlen((string) $value);
        }
        return $length <= $rule;
    }
348125
public static function lessThan(Validator $validator, $data, $pattern, $rule, $parameters)
    {
        $upperBound = Validator::getValue($data, $parameters[0]);
        if (null === $upperBound) {
            return;
        }
        foreach (Validator::getValues($data, $pattern) as $attribute => $value) {
            if (null === $value || empty($value)) {
                continue;
            }
            if ($value < $upperBound) {
                continue;
            }

            $validator->addError($attribute, $rule, [':value' => $value]);
        }
    }
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;
	}
758771
public function setRelation($name, $value, $data = [])
    {
        // 检测修改器
        $method = 'set' . Db::parseName($name, 1) . 'Attr';

        if (method_exists($this, $method)) {
            $value = $this->$method($value, array_merge($this->data, $data));
        }

        $this->relation[$name] = $value;

        return $this;
    }
726675
public function ruleValue($value = null)
    {
        if (\func_num_args() > 0) {
            if (null !== $value && $this->validateValue($value)) {
                $this->value = $value;
                $this->updateBound();

                return true;
            }
            return false;
        }
        return $this->value;
    }
376900
protected function _validateData($rule, $key, $data)
    {
        if (
            (is_callable($rule) && call_user_func_array($rule, [$key, $data, $this]))
            || @preg_match($rule, $data)
        ) {
            return true;
        }

        if ($rule instanceof Closure) {
            $reflection = new ReflectionFunction($rule);
            $rule       = $reflection->__toString();
        }

        $this->_errorsList[] = [
            'message'   => 'validation_mismatch',
            'key'       => $key,
            'data'      => $data,
            'rule'      => $rule,
        ];
        $this->_hasErrors = true;

        return false;
    }
483030
protected function extractInputFromRules($data, array $rules): array
    {
        if (\is_object($data)) {
            $data = (array)$data;
        }

        $result = [];
        $additional = [];
        $arrays = [];
        $isGlobalArray = false;

        foreach ($rules as $rule => $value) {
            if (Str::contains($rule, '.')) {
                $attributes = explode('.', $rule);
                $rule = array_shift($attributes);
                $key = implode('.', $attributes);

                if (\is_array($data)) {
                    if (array_key_exists($rule, $data)) {
                        $additional[$rule][$key] = $value;
                    } elseif ($rule === '*') {
                        $arrays[$key] = $value;
                    }
                }
            } elseif (\is_array($data) && array_key_exists($rule, $data)) {
                $result[$rule] = $data[$rule];
            } elseif ($rule === '*' && \is_array($data)) {
                $isGlobalArray = true;
            }
        }

        if (!empty($arrays)) {
            $result = [];
            foreach ($data as $item) {
                $result[] = $this->extractInputFromRules($item, $arrays);
            }

            return $result;
        } elseif ($isGlobalArray) {
            return $data;
        }

        foreach ($additional as $key => $item) {
            $result[$key] = $this->extractInputFromRules($data[$key], $item);
        }

        return $result;
    }
1143163
public function applyFilters($value, $rules = array())
    {
        $valueTO = $this->valueTO->forge($value);
        // loop through all the rules to validate $value.
        foreach ($rules as $rule => $parameter) {
            // skip rules with option as FALSE.
            if ($parameter === false) {
                continue;
            }
            $this->filter->apply($rule, $valueTO, $parameter);

            // loop break.
            if ($valueTO->getBreak()) {
                break;
            }
        }

        return $valueTO;
    }
1206895
public function getSanitize($data, $rules)
    {
        // iterate through each field
        foreach ($rules as $field => $rule)
        {
            // turn the listing of rules with a "|" separator into an array
            // yeah, $rule can contain multiple rules (ie, multiple php functions)
            $phpFunctions = explode('|', $rule);

            // iterate through each rule
            foreach($phpFunctions as $phpFunction)
            {
                $data[$field] = call_user_func_array($phpFunction, [$data[$field] ]);

                // debug
                //echo "<br>The field ".$field." is now = ".$data[$field]." (".$singleFunction.")";
            }
        }

        return $data;
    }
478569
protected function walkRuleChain($value, $rules)
    {
        foreach ($rules as $rule) {
            $filter = $this->filterLoader->getFilterForRule($rule);
            $value = $filter->apply($rule, $value);
        }

        return $value;
    }
472591
protected function in($value, $rule)
    {
        return in_array($value, is_array($rule) ? $rule : explode(',', $rule));
    }
1113338
public function between( $value, $rule )
	{
		if( is_string( $rule ) ){
			$rule = explode( ',', $rule );
		}
		list( $min, $max ) = $rule;
		return $value >= $min && $value <= $max;
	}
1196919
public function apply(Rule $rule, $value)
    {
        return $this->getZendInstance($rule->class, $rule->zendOptions)->filter($value);
    }
937451
private function validateByRule( $field, $value, $rule, $message = null )
    {
        $ruleClassName = $this->ruleToClassName($this->getRuleName($rule));

        if (!class_exists($ruleClassName)) {
            return false;
        }

        $ruleObject = new $ruleClassName();
        if ($this->isLengthRule($rule)) {
            $ruleObject->setLength($this->extractLength($rule));;
        } else {
            if ($this->isSameRule($rule)) {
                $ruleObject->prepareRule($this->fields, $this->extractSame($rule));
            }
        }
        $result = $ruleObject->run($this->keyToLabel($field), $value, $message);

        if (!$result) {
            static::$errors[ $field ] = $ruleObject->message();
        }

        return $result;
    }
351915
public function validate(array $data, array $rules, $firstErrBreak = true)
	{
		$this->errors = [];

		foreach ($rules as $field => $fieldRules) {
            // 待验证字符串
            $value = @$data[$field];

            if (isset($fieldRules['message'])) {
                // 字段的验证规则为一维数组
                if (false === $this->validateItem($value, $fieldRules)) {
                    $this->errors[] = $fieldRules['message'];
                    if ($firstErrBreak) {
                        return false;
                    }
                }
            } else {
                // 字段的验证规则为二维数组
                foreach ($fieldRules as $ruleItem) {
                    if (false === $this->validateItem($value, $ruleItem)) {
                        $this->errors[] = @$ruleItem['message'];
                        if ($firstErrBreak) {
                            return false;
                        }
                    }
                }
            }
        }

		return empty($this->errors);
	}