From 9b5dbbea80b4b6adc82107f424e948ed37e7d01d Mon Sep 17 00:00:00 2001 From: Thorsten Ott Date: Wed, 24 Mar 2021 11:52:09 +0100 Subject: [PATCH] Account for existing env() methods and use them as a default where possible --- src/Configuration/DotEnvConfiguration.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Configuration/DotEnvConfiguration.php b/src/Configuration/DotEnvConfiguration.php index 74db6f4a..2c18f640 100644 --- a/src/Configuration/DotEnvConfiguration.php +++ b/src/Configuration/DotEnvConfiguration.php @@ -55,7 +55,14 @@ public function __construct($path = '.') */ private function env($key, $default = null) { - $value = $_ENV[$key] ?? null; + + // Fallback for frameworks like Laravel as the $_ENV method might not work in all + // circumstances. ie when running scheduled jobs. + if (function_exists('env') && is_callable('env')) { + $value = call_user_func('env', $key) ?? null; + } else { + $value = $_ENV[$key] ?? null; + } if ($value === false) { return $default;