Skip to content

Commit

Permalink
改进多环境变量定义
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Apr 16, 2021
1 parent a6720bb commit 55264dd
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/think/App.php
Expand Up @@ -413,6 +413,22 @@ public function getBeginMem(): int
return $this->beginMem;
}

/**
* 加载环境变量定义
* @access public
* @param string $envName 环境标识
* @return void
*/
public function loadEnv(string $envName = ''): void
{
// 加载环境变量
$envFile = $envName ? $this->rootPath . '.env.' . $envName : $this->rootPath . '.env';

if (is_file($envFile)) {
$this->env->load($envFile);
}
}

/**
* 初始化应用
* @access public
Expand All @@ -425,10 +441,7 @@ public function initialize()
$this->beginTime = microtime(true);
$this->beginMem = memory_get_usage();

// 加载环境变量
if (is_file($this->rootPath . $this->envName . '.env')) {
$this->env->load($this->rootPath . $this->envName . '.env');
}
$this->loadEnv($this->envName);

$this->configExt = $this->env->get('config_ext', '.php');

Expand Down Expand Up @@ -608,7 +621,7 @@ public function parseClass(string $layer, string $name): string
* 是否运行在命令行下
* @return bool
*/
public function runningInConsole()
public function runningInConsole(): bool
{
return php_sapi_name() === 'cli' || php_sapi_name() === 'phpdbg';
}
Expand Down

0 comments on commit 55264dd

Please sign in to comment.