Skip to content

Commit f8296b7

Browse files
committed
bug symfony#59136 [DependencyInjection] Reset env vars with kernel.reset (faizanakram99)
This PR was merged into the 7.1 branch. Discussion ---------- [DependencyInjection] Reset env vars with `kernel.reset` | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix symfony#59128 | License | MIT As mentioned in symfony#59128 and symfony#54666 (comment) (and proceeding comments), EnvVarProcessor isn't tagged with kernel.reset, hence its reset method is never called in ServicesResetter. Another issue was that env vars are cached high up in stack (in Container class) and even if EnvVarProcessor's cached env vars are cleared, env var loaders still won't be called as env var loaders are called only for missing env keys. This PR fixes symfony#59128 by adding the missing tag and also clears "env cache" of Container in `EnvVarProcessor::reset()` method (i.e. whenever env vars of EnvVarProcessor are cleared). This is a safe change and won't break existing apps using symfony messenger. cc `@bendavies` Commits ------- 4c9e1a4 fix(dependency-injection): reset env vars with kernel.reset
2 parents 9f770a7 + 4c9e1a4 commit f8296b7

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/services.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class_exists(WorkflowEvents::class) ? WorkflowEvents::ALIASES : []
195195
tagged_iterator('container.env_var_loader'),
196196
])
197197
->tag('container.env_var_processor')
198+
->tag('kernel.reset', ['method' => 'reset'])
198199

199200
->set('slugger', AsciiSlugger::class)
200201
->args([

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,14 @@ public function reset(): void
290290
$this->envCache = $this->services = $this->factories = $this->privates = [];
291291
}
292292

293+
/**
294+
* @internal
295+
*/
296+
public function resetEnvCache(): void
297+
{
298+
$this->envCache = [];
299+
}
300+
293301
/**
294302
* Gets all service ids.
295303
*

src/Symfony/Component/DependencyInjection/EnvVarProcessor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,5 +374,9 @@ public function reset(): void
374374
{
375375
$this->loadedVars = [];
376376
$this->loaders = $this->originalLoaders;
377+
378+
if ($this->container instanceof Container) {
379+
$this->container->resetEnvCache();
380+
}
377381
}
378382
}

0 commit comments

Comments
 (0)