8000 bug #45188 [Dotenv] Fix bootEnv() override with .env.local.php when t… · symfony/symfony@9b7aac3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9b7aac3

Browse files
bug #45188 [Dotenv] Fix bootEnv() override with .env.local.php when the env key already exists (fancyweb)
This PR was merged into the 5.4 branch. Discussion ---------- [Dotenv] Fix bootEnv() override with .env.local.php when the env key already exists | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - If `$_SERVER['APP_ENV'] = 'foo'` and `.env.local.php` exists and returns `'APP_ENV' => 'prod'`, the override does not work. Commits ------- 1f29087 [Dotenv] Fix bootEnv() override with .env.local.php when the env key already exists
2 parents 79d1101 + 1f29087 commit 9b7aac3

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Symfony/Component/Dotenv/Dotenv.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function bootEnv(string $path, string $defaultEnv = 'dev', array $testEnv
151151
$env = is_file($p) ? include $p : null;
152152
$k = $this->envKey;
153153

154-
if (\is_array($env) && (!isset($env[$k]) || ($_SERVER[$k] ?? $_ENV[$k] ?? $env[$k]) === $env[$k])) {
154+
if (\is_array($env) && ($overrideExistingVars || !isset($env[$k]) || ($_SERVER[$k] ?? $_ENV[$k] ?? $env[$k]) === $env[$k])) {
155155
$this->populate($env, $overrideExistingVars);
156156
} else {
157157
$this->loadEnv($path, $k, $defaultEnv, $testEnvs, $overrideExistingVars);

src/Symfony/Component/Dotenv/Tests/DotenvTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,13 @@ public function testBootEnv()
587587
$this->assertSame('BAR', $_SERVER['FOO']);
588588
$this->assertSame('1', $_SERVER['TEST_APP_DEBUG']);
589589
$this->assertSame('localphpNEW_VALUE', $_SERVER['EXISTING_KEY']);
590+
591+
$resetContext();
592+
$_SERVER['TEST_APP_ENV'] = 'ccc';
593+
(new Dotenv('TEST_APP_ENV', 'TEST_APP_DEBUG'))->bootEnv($path, 'dev', ['test'], true);
594+
$this->assertSame('BAR', $_SERVER['FOO']);
595+
$this->assertSame('1', $_SERVER['TEST_APP_DEBUG']);
596+
$this->assertSame('localphpNEW_VALUE', $_SERVER['EXISTING_KEY']);
590597
unlink($path.'.local.php');
591598

592599
$resetContext();

0 commit comments

Comments
 (0)
0