Skip to content

Commit 0c2714d

Browse files
bug #34862 [FrameworkBundle][ContainerLintCommand] Reinitialize bundles when the container is reprepared (fancyweb)
This PR was merged into the 4.4 branch. Discussion ---------- [FrameworkBundle][ContainerLintCommand] Reinitialize bundles when the container is reprepared | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Some bundles extensions are "instances dependents", eg they cache service registrations (eg: https://github.com/symfony/symfony/blob/70dec3c8a39181dcf403fb54b92c065f55edfa3c/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php#L743). Launching the lint command loads all bundles a first time, just to be able to run the command. Then, when we build the container again for the lint command, it loads all bundles a second time. But since it's the same bundles instances, some services are not registered, leading to missing services in `CheckExceptionOnInvalidReferenceBehaviorPass`. Commits ------- 31975e4981 [FrameworkBundle][ContainerLintCommand] Reinitialize bundles when the container is reprepared
2 parents 4f63896 + 5dc07e4 commit 0c2714d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Command/ContainerLintCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ private function getContainerBuilder(): ContainerBuilder
6969
$kernel = $this->getApplication()->getKernel();
7070

7171
if (!$kernel->isDebug() || !(new ConfigCache($kernel->getContainer()->getParameter('debug.container.dump'), true))->isFresh()) {
72-
$buildContainer = \Closure::bind(function () { return $this->buildContainer(); }, $kernel, \get_class($kernel));
72+
$buildContainer = \Closure::bind(function (): ContainerBuilder {
73+
$this->initializeBundles();
74+
75+
return $this->buildContainer();
76+
}, $kernel, \get_class($kernel));
7377
$container = $buildContainer();
7478
} else {
7579
(new XmlFileLoader($container = new ContainerBuilder($parameterBag = new EnvPlaceholderParameterBag()), new FileLocator()))->load($kernel->getContainer()->getParameter('debug.container.dump'));

0 commit comments

Comments
 (0)