Skip to content

Commit

Permalink
Chore: Refactor the env loader for improved efficiency.
Browse files Browse the repository at this point in the history
  • Loading branch information
3m1n3nc3 committed Sep 4, 2024
1 parent d0716c2 commit df3b193
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Cuttly.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -116,4 +117,4 @@ public static function jsonValidate($json, $depth = 512, $flags = 0)
return false;
}
}
}
}

0 comments on commit df3b193

Please sign in to comment.