Skip to content

Commit

Permalink
bug #53989 [FrameworkBundle] Fix config builder with extensions exten…
Browse files Browse the repository at this point in the history
…ded in `build()` (HypeMC)

This PR was merged into the 5.4 branch.

Discussion
----------

[FrameworkBundle] Fix config builder with extensions extended in `build()`

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #53987
| License       | MIT

The problem is caused by the fact that the Security bundle configuration can be extended in any `Bundle::build()` or the `Kernel::build()` methods.

Commits
-------

7053385 [FrameworkBundle] Fix config builder with extensions extended in `build()`
  • Loading branch information
nicolas-grekas committed Feb 20, 2024
2 parents 1ba6fe3 + 7053385 commit 6438969
Show file tree
Hide file tree
Showing 2 changed files with 359 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBag;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\KernelInterface;

/**
Expand Down Expand Up @@ -49,12 +50,27 @@ public function warmUp(string $cacheDir)
{
$generator = new ConfigBuilderGenerator($this->kernel->getBuildDir());

foreach ($this->kernel->getBundles() as $bundle) {
$extension = $bundle->getContainerExtension();
if (null === $extension) {
continue;
if ($this->kernel instanceof Kernel) {
/** @var ContainerBuilder $container */
$container = \Closure::bind(function (Kernel $kernel) {
$containerBuilder = $kernel->getContainerBuilder();
$kernel->prepareContainer($containerBuilder);

return $containerBuilder;
}, null, $this->kernel)($this->kernel);

$extensions = $container->getExtensions();
} else {
$extensions = [];
foreach ($this->kernel->getBundles() as $bundle) {
$extension = $bundle->getContainerExtension();
if (null !== $extension) {
$extensions[] = $extension;
}
}
}

foreach ($extensions as $extension) {
try {
$this->dumpExtension($extension, $generator);
} catch (\Exception $e) {
Expand Down

0 comments on commit 6438969

Please sign in to comment.