Skip to content

Commit 48dc60b

Browse files
authored
Merge pull request #43 from qnnp-me/main
feat: 检测加载 .env 配置文件
2 parents 20d8623 + 96e43c5 commit 48dc60b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/webman

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use Webman\Config;
55
use Webman\Console\Command;
66
use Webman\Console\Util;
77
use support\Container;
8+
use Dotenv\Dotenv;
89
if (!Phar::running()) {
910
chdir(__DIR__);
1011
}
@@ -13,6 +14,15 @@ require_once __DIR__ . '/vendor/autoload.php';
1314
if (!$appConfigFile = config_path('app.php')) {
1415
throw new RuntimeException('Config file not found: app.php');
1516
}
17+
18+
if (class_exists(Dotenv::class) && file_exists(run_path('.env'))) {
19+
if (method_exists(Dotenv::class, 'createUnsafeImmutable')) {
20+
Dotenv::createUnsafeImmutable(run_path())->load();
21+
} else {
22+
Dotenv::createMutable(run_path())->load();
23+
}
24+
}
25+
1626
$appConfig = require $appConfigFile;
1727
if ($timezone = $appConfig['default_timezone'] ?? '') {
1828
date_default_timezone_set($timezone);

0 commit comments

Comments
 (0)