Skip to content

Commit c371297

Browse files
committed
Fix EnvVar not loaded when Loader requires an env var
1 parent 642c7ff commit c371297

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/Symfony/Component/DependencyInjection/EnvVarProcessor.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
2222
{
2323
private $container;
2424
private $loaders;
25+
private $loadedLoaderIndex = 0;
2526
private $loadedVars = [];
2627

2728
/**
@@ -30,8 +31,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
3031
public function __construct(ContainerInterface $container, \Traversable $loaders = null)
3132
{
3233
$this->container = $container;
33-
$this->loaders = new \IteratorIterator($loaders ?? new \ArrayIterator());
34-
$this->loaders = $this->loaders->getInnerIterator();
34+
$this->loaders = $loaders ?? new \ArrayIterator();
3535
}
3636

3737
/**
@@ -145,11 +145,22 @@ public function getEnv($prefix, $name, \Closure $getEnv)
145145
$this->loaders = new \ArrayIterator();
146146

147147
try {
148-
while ((false === $env || null === $env) && $loaders->valid()) {
149-
$loader = $loaders->current();
150-
$loaders->next();
148+
$index = 0;
149+
$ended = true;
150+
foreach ($loaders as $loader) {
151+
if ($index++ < $this->loadedLoaderIndex) {
152+
continue;
153+
}
151154
$this->loadedVars[] = $vars = $loader->loadEnvVars();
155+
$this->loadedLoaderIndex = $index;
152156
$env = $vars[$name] ?? false;
157+
if (false !== $env) {
158+
$ended = false;
159+
break;
160+
}
161+
}
162+
if ($ended) {
163+
$loaders = new \ArrayIterator();
153164
}
154165
} catch (ParameterCircularReferenceException $e) {
155166
// skip loaders that need an env var that is not defined

0 commit comments

Comments
 (0)