10000 Fix env fallback to an unresolved variable · symfony/symfony@ad6df01 · GitHub
[go: up one dir, main page]

Skip to content

Commit ad6df01

Browse files
jderussenicolas-grekas
authored andcommitted
Fix env fallback to an unresolved variable
1 parent 8a60907 commit ad6df01

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,11 +1534,15 @@ protected function getEnv($name)
15341534
return $value;
15351535
}
15361536

1537-
foreach ($bag->getEnvPlaceholders() as $env => $placeholders) {
1538-
if (isset($placeholders[$value])) {
1539-
$bag = new ParameterBag($bag->all());
1537+
$envPlaceholders = $bag->getEnvPlaceholders();
1538+
if (isset($envPlaceholders[$name][$value])) {
1539+
$bag = new ParameterBag($bag->all());
15401540

1541-
return $bag->unescapeValue($bag->get("env($name)"));
1541+
return $bag->unescapeValue($bag->get("env($name)"));
1542+
}
1543+
foreach ($envPlaceholders as $env => $placeholders) {
1544+
if (isset($placeholders[$value])) {
1545+
return $this->getEnv($env);
15421546
}
15431547
}
15441548

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,20 @@ public function testDynamicEnv()
738738
$this->assertSame('someFooBar', $container->getParameter('baz'));
739739
}
740740

741+
public function testFallbackEnv()
742+
{
743+
putenv('DUMMY_FOO=foo');
744+
745+
$container = new ContainerBuilder();
746+
$container->setParameter('foo', '%env(DUMMY_FOO)%');
747+
$container->setParameter('bar', 'bar%env(default:foo:DUMMY_BAR)%');
748+
749+
$container->compile(true);
750+
putenv('DUMMY_FOO');
751+
752+
$this->assertSame('barfoo', $container->getParameter('bar'));
753+
}
754+
741755
public function testCastEnv()
742756
{
743757
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)
0