mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
改进Config类支持配置CONF_EXT常量
This commit is contained in:
1
base.php
1
base.php
@@ -32,6 +32,7 @@ defined('CACHE_PATH') or define('CACHE_PATH', RUNTIME_PATH . 'cache' . DS);
|
||||
defined('TEMP_PATH') or define('TEMP_PATH', RUNTIME_PATH . 'temp' . DS);
|
||||
defined('VENDOR_PATH') or define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS);
|
||||
defined('EXT') or define('EXT', '.php');
|
||||
defined('CONF_EXT') or define('CONF_EXT', EXT); // 配置文件后缀
|
||||
defined('MODEL_LAYER') or define('MODEL_LAYER', 'model');
|
||||
defined('VIEW_LAYER') or define('VIEW_LAYER', 'view');
|
||||
defined('CONTROLLER_LAYER') or define('CONTROLLER_LAYER', 'controller');
|
||||
|
||||
@@ -263,17 +263,17 @@ class App
|
||||
} else {
|
||||
$path = APP_PATH . $module;
|
||||
// 加载模块配置
|
||||
$config = Config::load(APP_PATH . $module . 'config' . EXT);
|
||||
$config = Config::load(APP_PATH . $module . 'config' . CONF_EXT);
|
||||
|
||||
// 加载应用状态配置
|
||||
if ($config['app_status']) {
|
||||
$config = Config::load(APP_PATH . $module . $config['app_status'] . EXT);
|
||||
$config = Config::load(APP_PATH . $module . $config['app_status'] . CONF_EXT);
|
||||
}
|
||||
|
||||
// 读取扩展配置文件
|
||||
if ($config['extra_config_list']) {
|
||||
foreach ($config['extra_config_list'] as $name => $file) {
|
||||
$filename = $path . $file . EXT;
|
||||
$filename = $path . $file . CONF_EXT;
|
||||
Config::load($filename, is_string($name) ? $name : pathinfo($filename, PATHINFO_FILENAME));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,16 +31,17 @@ class Config
|
||||
* 解析配置文件或内容
|
||||
* @param string $config 配置文件路径或内容
|
||||
* @param string $type 配置解析类型
|
||||
* @param string $name 配置名(如设置即表示二级配置)
|
||||
* @param string $range 作用域
|
||||
*/
|
||||
public static function parse($config, $type = '', $range = '')
|
||||
public static function parse($config, $type = '', $name = '', $range = '')
|
||||
{
|
||||
$range = $range ?: self::$range;
|
||||
if (empty($type)) {
|
||||
$type = pathinfo($config, PATHINFO_EXTENSION);
|
||||
}
|
||||
$class = (false === strpos($type, '\\')) ? '\\think\\config\\driver\\' . ucwords($type) : $type;
|
||||
self::set((new $class())->parse($config), '', $range);
|
||||
self::set((new $class())->parse($config), $name, $range);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +60,12 @@ class Config
|
||||
if (is_file($file)) {
|
||||
// 记录加载信息
|
||||
APP_DEBUG && Log::record('[ CONFIG ] ' . $file, 'info');
|
||||
return self::set(include $file, $name, $range);
|
||||
$type = pathinfo($file, PATHINFO_EXTENSION);
|
||||
if ('php' != $type) {
|
||||
return self::parse($config, $type, $name, $range);
|
||||
} else {
|
||||
return self::set(include $file, $name, $range);
|
||||
}
|
||||
} else {
|
||||
return self::$config[$range];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user