From df3b19314e08cc8b39e4b2bb288a17fd1369056b Mon Sep 17 00:00:00 2001 From: 3m1n3nc3 Date: Wed, 4 Sep 2024 15:40:10 +0100 Subject: [PATCH] Chore: Refactor the env loader for improved efficiency. --- src/Cuttly.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Cuttly.php b/src/Cuttly.php index eb3f576..d218044 100644 --- a/src/Cuttly.php +++ b/src/Cuttly.php @@ -27,14 +27,15 @@ public function init(): self private static function env($key): ?string { + if (function_exists('env')) { + return env($key); + } - $repository = RepositoryBuilder::createWithDefaultAdapters()->make(); - - $dotenv = Dotenv::create($repository, static::getEnvPath()); + $repository = RepositoryBuilder::createWithDefaultAdapters()->immutable()->make(); - $env = $dotenv->safeLoad(); + Dotenv::create($repository, static::getEnvPath())->safeLoad(); - return $env[$key] ?? null; + return $_SERVER[$key] ?? null; } /** @@ -116,4 +117,4 @@ public static function jsonValidate($json, $depth = 512, $flags = 0) return false; } } -} +} \ No newline at end of file