环境变量定义文件更改为 .env 不再使用php数组方式定义 改为兼容ini格式定义(支持数组方式)

This commit is contained in:
thinkphp
2016-08-31 11:43:05 +08:00
parent b59649d128
commit 389b4c7dd2
2 changed files with 10 additions and 8 deletions

View File

@@ -38,18 +38,20 @@ define('IS_WIN', strpos(PHP_OS, 'WIN') !== false);
require CORE_PATH . 'Loader.php';
// 加载环境变量配置文件
if (is_file(ROOT_PATH . 'env' . EXT)) {
$env = include ROOT_PATH . 'env' . EXT;
if (is_file(ROOT_PATH . '.env')) {
$env = parse_ini_file(ROOT_PATH . '.env', true);
foreach ($env as $key => $val) {
$name = ENV_PREFIX . strtoupper($key);
if (is_bool($val)) {
$val = $val ? 1 : 0;
} elseif (!is_scalar($val)) {
continue;
if (is_array($val)) {
foreach ($val as $k => $v) {
$item = $name . '_' . strtoupper($k);
putenv("$item=$v");
}
} else {
putenv("$name=$val");
}
}
}
// 注册自动加载
\think\Loader::register();

View File

@@ -1227,7 +1227,7 @@ class Query
/**
* 设置查询数据不存在是否抛出异常
* @access public
* @param bool $fail 是否严格检查字段
* @param bool $fail 数据不存在是否抛出异常
* @return $this
*/
public function failException($fail = true)