Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a4b0dfc

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

File tree

2 files changed

+13
-3
lines changed
Filter options

2 files changed

+13
-3
lines changed

‎src/Symfony/Component/Dotenv/Dotenv.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Dotenv/Dotenv.php
+3-3Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Dotenv/Tests/DotenvTest.php
+10Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.