mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 07:12:47 +08:00
改进Lang类 去除无用的 traits\model
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
|
||||
namespace think;
|
||||
|
||||
use think\Config;
|
||||
|
||||
class Input
|
||||
{
|
||||
// 全局过滤规则
|
||||
@@ -58,7 +60,7 @@ class Input
|
||||
}
|
||||
return self::data($_PUT, $name, $default, $filter, $merge);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取delete变量
|
||||
* @param string $name 数据名称
|
||||
@@ -192,7 +194,7 @@ class Input
|
||||
public static function path($name = '', $default = null, $filter = null, $merge = false)
|
||||
{
|
||||
if (!empty($_SERVER['PATH_INFO'])) {
|
||||
$depr = \think\Config::get('pathinfo_depr');
|
||||
$depr = Config::get('pathinfo_depr');
|
||||
$input = explode($depr, trim($_SERVER['PATH_INFO'], $depr));
|
||||
return self::data($input, $name, $default, $filter, $merge);
|
||||
} else {
|
||||
@@ -393,7 +395,7 @@ class Input
|
||||
{
|
||||
if (is_null(static::$filters)) {
|
||||
// 从配置项中读取
|
||||
$filters = \think\Config::get('default_filter');
|
||||
$filters = Config::get('default_filter');
|
||||
static::$filters = empty($filters) ? [] : (is_array($filters) ? $filters : explode(',', $filters));
|
||||
}
|
||||
return static::$filters;
|
||||
|
||||
@@ -11,17 +11,23 @@
|
||||
|
||||
namespace think;
|
||||
|
||||
use think\Config;
|
||||
use think\Cookie;
|
||||
use think\Log;
|
||||
|
||||
class Lang
|
||||
{
|
||||
// 语言参数
|
||||
// 语言数据
|
||||
private static $lang = [];
|
||||
// 语言作用域
|
||||
private static $range = 'zh-cn';
|
||||
// 语言自动侦测的变量
|
||||
protected static $langDetectVar = 'lang';
|
||||
// 语言Cookie变量
|
||||
protected static $langCookieVar = 'think_var';
|
||||
// 允许语言列表
|
||||
protected static $allowLangList = [];
|
||||
|
||||
// 设定语言参数的作用域(语言)
|
||||
// 设定当前的语言
|
||||
public static function range($range = '')
|
||||
{
|
||||
if ('' == $range) {
|
||||
@@ -35,7 +41,7 @@ class Lang
|
||||
* 设置语言定义(不区分大小写)
|
||||
* @param string|array $name 语言变量
|
||||
* @param string $value 语言值
|
||||
* @param string $range 作用域
|
||||
* @param string $range 语言作用域
|
||||
* @return mixed
|
||||
*/
|
||||
public static function set($name, $value = null, $range = '')
|
||||
@@ -55,7 +61,7 @@ class Lang
|
||||
/**
|
||||
* 加载语言定义(不区分大小写)
|
||||
* @param string $file 语言文件
|
||||
* @param string $range 作用域
|
||||
* @param string $range 语言作用域
|
||||
* @return mixed
|
||||
*/
|
||||
public static function load($file, $range = '')
|
||||
@@ -89,7 +95,7 @@ class Lang
|
||||
* 获取语言定义(不区分大小写)
|
||||
* @param string|null $name 语言变量
|
||||
* @param array $vars 变量替换
|
||||
* @param string $range 作用域
|
||||
* @param string $range 语言作用域
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get($name = null, $vars = [], $range = '')
|
||||
@@ -133,25 +139,53 @@ class Lang
|
||||
public static function detect()
|
||||
{
|
||||
// 自动侦测设置获取语言选择
|
||||
$langCookieVar = Config::get('lang_cookie_var');
|
||||
$langDetectVar = Config::get('lang_detect_var');
|
||||
$langSet = '';
|
||||
if (isset($_GET[$langDetectVar])) {
|
||||
$langSet = '';
|
||||
if (isset($_GET[self::$langDetectVar])) {
|
||||
// url中设置了语言变量
|
||||
$langSet = strtolower($_GET[$langDetectVar]);
|
||||
Cookie::set($langCookieVar, $langSet, 3600);
|
||||
} elseif (Cookie::get($langCookieVar)) {
|
||||
$langSet = strtolower($_GET[self::$langDetectVar]);
|
||||
Cookie::set(self::$langCookieVar, $langSet, 3600);
|
||||
} elseif (Cookie::get(self::$langCookieVar)) {
|
||||
// 获取上次用户的选择
|
||||
$langSet = strtolower(Cookie::get($langCookieVar));
|
||||
$langSet = strtolower(Cookie::get(self::$langCookieVar));
|
||||
} elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||
// 自动侦测浏览器语言
|
||||
preg_match('/^([a-z\d\-]+)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches);
|
||||
$langSet = strtolower($matches[1]);
|
||||
Cookie::set($langCookieVar, $langSet, 3600);
|
||||
Cookie::set(self::$langCookieVar, $langSet, 3600);
|
||||
}
|
||||
if (in_array($langSet, Config::get('lang_list'))) {
|
||||
if (empty(self::$allowLangList) || in_array($langSet, self::$allowLangList)) {
|
||||
// 合法的语言
|
||||
self::$range = $langSet;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置语言自动侦测的变量
|
||||
* @param string $var 变量名称
|
||||
* @return void
|
||||
*/
|
||||
public static function setLangDetectVar($var)
|
||||
{
|
||||
self::$langDetectVar = $var;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置语言的cookie保存变量
|
||||
* @param string $var 变量名称
|
||||
* @return void
|
||||
*/
|
||||
public static function setLangCookieVar($var)
|
||||
{
|
||||
self::$langCookieVar = $var;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置允许的语言列表
|
||||
* @param array $list 语言列表
|
||||
* @return void
|
||||
*/
|
||||
public static function setAllowLangList($list)
|
||||
{
|
||||
self::$allowLangList = $list;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user