Skip to content

Commit

Permalink
[Dotenv]: search variable values in _ENV first then env file
Browse files Browse the repository at this point in the history
  • Loading branch information
soufianZantar committed Aug 5, 2019
1 parent 2d594d5 commit a4b0dfc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Symfony/Component/Dotenv/Dotenv.php
Expand Up @@ -446,12 +446,12 @@ private function resolveVariables(string $value)
}

$name = $matches['name'];
if (isset($this->values[$name])) {
if (isset($_ENV[$name])) {
$value = $_ENV[$name];
} elseif (isset($this->values[$name])) {
$value = $this->values[$name];
} elseif (isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')) {
$value = $_SERVER[$name];
} elseif (isset($_ENV[$name])) {
$value = $_ENV[$name];
} else {
$value = (string) getenv($name);
}
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/Dotenv/Tests/DotenvTest.php
Expand Up @@ -430,4 +430,14 @@ public function testDoNotUsePutenv()
$this->assertSame('no', $_ENV['TEST_USE_PUTENV']);
$this->assertFalse(getenv('TEST_USE_PUTENV'));
}

public function testGetVariablesValueFromEnvFirst()
{
$_ENV['APP_ENV'] = 'prod';
$dotenv = new Dotenv(true);
$test ="APP_ENV=dev\nTEST=foo_\${APP_ENV}";
$values = $dotenv->parse($test);

$this->assertSame('foo_prod', $values['TEST']);
}
}

0 comments on commit a4b0dfc

Please sign in to comment.