src/Leevel/Validate/Validator.php
protected function doValidateItem(string $field, string $rule)
    {
        list($rule, $parameter) = $this->parseRule($rule);

        if ('' === $rule) {
            return;
        }

        $fieldValue = $this->getFieldValue($field);

        // 默认情况下存在即验证，没有设置字段则跳过
        if (!$this->hasFieldValue($field) &&
            $this->hasFieldRuleWithoutParameter($field, static::CONDITION_EXISTS)) {
            return;
        }

        // 值不为空就验证，那么为的空的值将会跳过
        if (empty($fieldValue) &&
            $this->hasFieldRuleWithoutParameter($field, static::CONDITION_VALUE)) {
            return;
        }

        if (class_exists($fn = __NAMESPACE__.'\\Helper\\validate_'.$rule)) {
            if (!$fn($fieldValue, $parameter, $this, $field)) {
                $this->addFailure($field, $rule, $parameter);

                return false;
            }
        } elseif (class_exists($className = __NAMESPACE__.'\\'.($camelizeRule = ucwords(camelize($rule))).'Rule')) {
            if ($this->container) {
                $validateRule = $this->container->make($className);
            } else {
                $validateRule = new $className();
            }

            if (false === $validateRule->validate($fieldValue, $parameter, $this, $field)) {
                $this->addFailure($field, $rule, $parameter);

                return false;
            }
        } elseif (!$this->{'validate'.$camelizeRule}($fieldValue, $parameter, $this, $field)) {
            $this->addFailure($field, $rule, $parameter);

            return false;
        }

        unset($fieldValue);

        return true;
    }
protected function doValidateItem(string $field, string $rule)
    {
        list($rule, $parameter) = $this->parseRule($rule);

        if ('' === $rule) {
            return;
        }

        $fieldValue = $this->getFieldValue($field);

        // 默认情况下存在即验证，没有设置字段则跳过
        if (!$this->hasFieldValue($field) &&
            $this->hasFieldRuleWithoutParameter($field, static::CONDITION_EXISTS)) {
            return;
        }

        // 值不为空就验证，那么为的空的值将会跳过
        if (empty($fieldValue) &&
            $this->hasFieldRuleWithoutParameter($field, static::CONDITION_VALUE)) {
            return;
        }

        if (class_exists($fn = __NAMESPACE__.'\\Helper\\validate_'.$rule)) {
            if (!$fn($fieldValue, $parameter, $this, $field)) {
                $this->addFailure($field, $rule, $parameter);

                return false;
            }
        } elseif (class_exists($className = __NAMESPACE__.'\\'.($camelizeRule = ucwords(camelize($rule))).'Rule')) {
            if ($this->container) {
                $validateRule = $this->container->make($className);
            } else {
                $validateRule = new $className();
            }

            if (false === $validateRule->validate($fieldValue, $parameter, $this, $field)) {
                $this->addFailure($field, $rule, $parameter);

                return false;
            }
        } elseif (!$this->{'validate'.$camelizeRule}($fieldValue, $parameter, $this, $field)) {
            $this->addFailure($field, $rule, $parameter);

            return false;
        }

        unset($fieldValue);

        return true;
    }
验证字段规则.

@param string $field
@param string $rule

@return bool|void