Skip to content

Commit

Permalink
♻️ 重構(Schema.php):優化環境變數加載邏輯以避免重複加載
Browse files Browse the repository at this point in the history
這次修改的目的是在加載環境變數之前檢查`DATABASE_HOSTNAME`是否已經設置,這樣可以避免不必要的重複加載`.env`文件,從而提高代碼的效率和可讀性。
  • Loading branch information
mathsgod committed Jan 7, 2025
1 parent 98bbb28 commit 007ba6c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ static function Create(): Schema
}

//load from .env
$dotenv = \Dotenv\Dotenv::createImmutable(getcwd());
$dotenv->load();
if (!$_ENV["DATABASE_HOSTNAME"]) {
$dotenv = \Dotenv\Dotenv::createImmutable(getcwd());
$dotenv->load();
}

$host = $_ENV["DATABASE_HOSTNAME"];
$name = $_ENV["DATABASE_DATABASE"];
Expand Down

0 comments on commit 007ba6c

Please sign in to comment.