改进Config类的set方法

This commit is contained in:
thinkphp
2015-11-24 22:44:51 +08:00
parent b1c3fe5e9c
commit f6e3ec30a5

View File

@@ -16,7 +16,7 @@ class Config
// 配置参数 // 配置参数
private static $config = []; private static $config = [];
// 参数作用域 // 参数作用域
private static $range = '_sys_'; private static $range = '_sys_';
// 设定配置参数的作用域 // 设定配置参数的作用域
public static function range($range) public static function range($range)
@@ -35,9 +35,9 @@ class Config
} }
// 加载配置文件 // 加载配置文件
public static function load($file, $range = '') public static function load($file, $name = '', $range = '')
{ {
return self::set(include $file, '', $range); return self::set(include $file, $name, $range);
} }
// 检测配置是否存在 // 检测配置是否存在
@@ -100,8 +100,11 @@ class Config
return; return;
} elseif (is_array($name)) { } elseif (is_array($name)) {
// 批量设置 // 批量设置
self::$config[$range] = array_merge(self::$config[$range], array_change_key_case($name)); if (!empty($value)) {
return self::$config[$range]; return self::$config[$range][$value] = array_change_key_case($name);
} else {
return self::$config[$range] = array_merge(self::$config[$range], array_change_key_case($name));
}
} else { } else {
return null; // 避免非法参数 return null; // 避免非法参数
} }