think\Validate::getRuleMsg PHP Method

getRuleMsg() protected method

获取验证规则的错误提示信息
protected getRuleMsg ( string $attribute, string $title, string $type, mixed $rule ) : string
$attribute string 字段英文名
$title string 字段描述名
$type string 验证规则名称
$rule mixed 验证规则数据
return string
    protected function getRuleMsg($attribute, $title, $type, $rule)
    {
        if (isset($this->message[$attribute . '.' . $type])) {
            $msg = $this->message[$attribute . '.' . $type];
        } elseif (isset($this->message[$attribute])) {
            $msg = $this->message[$attribute];
        } elseif (isset(self::$typeMsg[$type])) {
            $msg = self::$typeMsg[$type];
        } else {
            $msg = $title . '规则错误';
        }
        if (is_string($msg) && strpos($msg, '{%')) {
            $msg = Lang::get(substr($msg, 2, -1));
        }
        if (is_string($msg) && false !== strpos($msg, ':')) {
            // 变量替换
            if (strpos($rule, ',')) {
                $array = array_pad(explode(',', $rule), 3, '');
            } else {
                $array = array_pad([], 3, '');
            }
            $msg = str_replace([':attribute', ':rule', ':1', ':2', ':3'], [$title, (string) $rule, $array[0], $array[1], $array[2]], $msg);
        }
        return $msg;
    }