8000 [DI] Impossible to set an environment variable and then an array as container parameter by Phantas0s · Pull Request #25333 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] Impossible to set an environment variable and then an array as container parameter #25333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
10 changes: 5 additions & 5 deletions src/Symfony/Component/DependencyInjection/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,11 @@ public function resolveEnvPlaceholders($value, $format = null, array &$usedEnvs
$format = '%%env(%s)%%';
}

$bag = $this->getParameterBag();
if (true === $format) {
$value = $bag->resolveValue($value);
}

if (is_array($value)) {
$result = array();
foreach ($value as $k => $v) {
Expand All @@ -1306,11 +1311,6 @@ public function resolveEnvPlaceholders($value, $format = null, array &$usedEnvs
if (!is_string($value)) {
return $value;
}

$bag = $this->getParameterBag();
if (true === $format) {
$value = $bag->resolveValue($value);
}
$envPlaceholders = $bag instanceof EnvPlaceholderParameterBag ? $bag->getEnvPlaceholders() : $this->envPlaceholders;

foreach ($envPlaceholders as $env => $placeholders) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,20 @@ public function testResolveEnvValues()
unset($_ENV['DUMMY_ENV_VAR'], $_SERVER['DUMMY_SERVER_VAR'], $_SERVER['HTTP_DUMMY_VAR']);
}

public function testResolveEnvValuesWithArray()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

risky test btw.. needs an assertion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You definitely need to assert something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some assertions. Sorry for that.

{
$_ENV['ANOTHER_DUMMY_ENV_VAR'] = 'dummy';

$container = new ContainerBuilder();
$container->setParameter('dummy', '%env(ANOTHER_DUMMY_ENV_VAR)%');
$container->setParameter('dummy2', array('1' => 'one', '2' => 'two'));

$container->resolveEnvPlaceholders('%dummy%', true);
$container->resolveEnvPlaceholders('%dummy2%', true);

unset($_ENV['ANOTHER_DUMMY_ENV_VAR']);
}

public function testCompileWithResolveEnv()
{
putenv('DUMMY_ENV_VAR=du%%y');
Expand Down
0