From be881b84d2d6934c8dbe25ae317e1924f089d780 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 6 Mar 2015 12:37:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ENV=5FPREFIX=E5=B8=B8?= =?UTF-8?q?=E9=87=8F=E7=94=A8=E4=BA=8E=E8=8E=B7=E5=8F=96=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E7=9A=84=E9=85=8D=E7=BD=AE=E5=89=8D=E7=BC=80?= =?UTF-8?q?=20=E6=94=B9=E8=BF=9B=E9=85=8D=E7=BD=AE=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=9A=84=E8=8E=B7=E5=8F=96=E6=96=B9=E6=B3=95=20=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=20=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E6=9C=89=E8=AE=BE=E7=BD=AE=E5=88=99=E4=BC=98=E5=85=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base.php | 1 + library/think/config.php | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) 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; } }