Skip to content

Commit

Permalink
Merge pull request #27958 from matt-allan/restore-getenv-support
Browse files Browse the repository at this point in the history
[5.8] Allow retrieving env variables with getenv
  • Loading branch information
taylorotwell authored Mar 21, 2019
2 parents 03e73f8 + be22b61 commit 3ee639d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Illuminate/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Dotenv\Environment\DotenvFactory;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\HigherOrderTapProxy;
use Dotenv\Environment\Adapter\PutenvAdapter;
use Dotenv\Environment\Adapter\EnvConstAdapter;
use Dotenv\Environment\Adapter\ServerConstAdapter;

Expand Down Expand Up @@ -642,7 +643,7 @@ function env($key, $default = null)
static $variables;

if ($variables === null) {
$variables = (new DotenvFactory([new EnvConstAdapter, new ServerConstAdapter]))->createImmutable();
$variables = (new DotenvFactory([new EnvConstAdapter, new PutEnvAdapter, new ServerConstAdapter]))->createImmutable();
}

return Option::fromValue($variables->get($key))
Expand Down
3 changes: 3 additions & 0 deletions tests/Foundation/Bootstrap/LoadEnvironmentVariablesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public function testCanLoad()
(new LoadEnvironmentVariables)->bootstrap($this->getAppMock('.env'));

$this->assertSame('BAR', env('FOO'));
$this->assertSame('BAR', getenv('FOO'));
$this->assertSame('BAR', $_ENV['FOO']);
$this->assertSame('BAR', $_SERVER['FOO']);
}

public function testCanFailSilent()
Expand Down

0 comments on commit 3ee639d

Please sign in to comment.