diff --git a/base.php b/base.php index e7580972..bdff5650 100644 --- a/base.php +++ b/base.php @@ -30,6 +30,7 @@ defined('MODEL_LAYER') || define('MODEL_LAYER', 'model'); defined('VIEW_LAYER') || define('VIEW_LAYER', 'view'); defined('CONTROLLER_LAYER') || define('CONTROLLER_LAYER', 'controller'); defined('APP_DEBUG') || define('APP_DEBUG', false); // 是否调试模式 +defined('ENV_PREFIX') || define('ENV_PREFIX', 'T_'); // 环境变量的配置前缀 // 应用模式 默认为普通模式 defined('APP_MODE') || define('APP_MODE', function_exists('saeAutoLoader') ? 'sae' : 'common'); diff --git a/library/think/config.php b/library/think/config.php index 9195f910..e574fe8c 100644 --- a/library/think/config.php +++ b/library/think/config.php @@ -13,7 +13,7 @@ namespace think; class Config { static private $config = []; // 配置参数 - static private $range = '_sys_'; // 参数作用域 + static private $range = '_sys_'; // 参数作用域 // 设定配置参数的作用域 static public function range($range){ @@ -57,10 +57,18 @@ class Config { } $name = strtolower($name); if (!strpos($name, '.')) { + // 判断环境变量 + if(isset($_ENV[ENV_PREFIX.$name])){ + return $_ENV[ENV_PREFIX.$name]; + } return isset(self::$config[$range][$name]) ? self::$config[$range][$name] : null; }else{ // 二维数组设置和获取支持 $name = explode('.', $name); + // 判断环境变量 + if(isset($_ENV[ENV_PREFIX.$name[0].'_'.$name[1]])){ + return $_ENV[ENV_PREFIX.$name[0].'_'.$name[1]]; + } return isset(self::$config[$range][$name[0]][$name[1]]) ? self::$config[$range][$name[0]][$name[1]] : null; } }