Skip to content

Commit a4b0dfc

Browse files
committed
[Dotenv]: search variable values in _ENV first then env file
1 parent 2d594d5 commit a4b0dfc

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/Symfony/Component/Dotenv/Dotenv.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,12 @@ private function resolveVariables(string $value)
446446
}
447447

448448
$name = $matches['name'];
449-
if (isset($this->values[$name])) {
449+
if (isset($_ENV[$name])) {
450+
$value = $_ENV[$name];
451+
} elseif (isset($this->values[$name])) {
450452
$value = $this->values[$name];
451453
} elseif (isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')) {
452454
$value = $_SERVER[$name];
453-
} elseif (isset($_ENV[$name])) {
454-
$value = $_ENV[$name];
455455
} else {
456456
$value = (string) getenv($name);
457457
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,4 +430,14 @@ public function testDoNotUsePutenv()
430430
$this->assertSame('no', $_ENV['TEST_USE_PUTENV']);
431431
$this->assertFalse(getenv('TEST_USE_PUTENV'));
432432
}
433+
434+
public function testGetVariablesValueFromEnvFirst()
435+
{
436+
$_ENV['APP_ENV'] = 'prod';
437+
$dotenv = new Dotenv(true);
438+
$test ="APP_ENV=dev\nTEST=foo_\${APP_ENV}";
439+
$values = $dotenv->parse($test);
440+
441+
$this->assertSame('foo_prod', $values['TEST']);
442+
}
433443
}

0 commit comments

Comments
 (0)