From 822d9a235b455f92137ee17784e48544c186e7e5 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 10 May 2016 14:39:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BConfig=E7=B1=BB=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E9=85=8D=E7=BD=AECONF=5FEXT=E5=B8=B8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base.php | 1 + library/think/App.php | 6 +++--- library/think/Config.php | 12 +++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/base.php b/base.php index a60c6988..41bdd7dd 100644 --- a/base.php +++ b/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'); diff --git a/library/think/App.php b/library/think/App.php index 61174bc6..242c6c87 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -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)); } } diff --git a/library/think/Config.php b/library/think/Config.php index 8be69135..8e181340 100644 --- a/library/think/Config.php +++ b/library/think/Config.php @@ -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]; }