From 0e9652a4bc4b9e89634a64cb6f9eeb64751d3ee2 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Tue, 13 Apr 2021 22:49:27 +0200 Subject: [PATCH] [FrameworkBundle] Add argument KernelInterface to BuildDebugContainerTrait::getContainerBuilder() --- .../FrameworkBundle/Command/AbstractConfigCommand.php | 5 +++-- .../FrameworkBundle/Command/BuildDebugContainerTrait.php | 5 ++--- .../FrameworkBundle/Command/ConfigDumpReferenceCommand.php | 2 +- .../FrameworkBundle/Command/ContainerDebugCommand.php | 7 ++++--- .../FrameworkBundle/Command/DebugAutowiringCommand.php | 4 ++-- .../Bundle/FrameworkBundle/Command/RouterDebugCommand.php | 7 ++++++- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php index bda4956df7..ba0328b6f7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php @@ -141,8 +141,9 @@ abstract class AbstractConfigCommand extends ContainerDebugCommand { // Re-build bundle manually to initialize DI extensions that can be extended by other bundles in their build() method // as this method is not called when the container is loaded from the cache. - $container = $this->getContainerBuilder(); - $bundles = $this->getApplication()->getKernel()->getBundles(); + $kernel = $this->getApplication()->getKernel(); + $container = $this->getContainerBuilder($kernel); + $bundles = $kernel->getBundles(); foreach ($bundles as $bundle) { if ($extension = $bundle->getContainerExtension()) { $container->registerExtension($extension); diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/BuildDebugContainerTrait.php b/src/Symfony/Bundle/FrameworkBundle/Command/BuildDebugContainerTrait.php index 8d6ca98fab..7f2e0c871b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/BuildDebugContainerTrait.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/BuildDebugContainerTrait.php @@ -16,6 +16,7 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\HttpKernel\KernelInterface; /** * @internal @@ -32,14 +33,12 @@ trait BuildDebugContainerTrait * * @throws \LogicException */ - protected function getContainerBuilder(): ContainerBuilder + protected function getContainerBuilder(KernelInterface $kernel): ContainerBuilder { if ($this->containerBuilder) { return $this->containerBuilder; } - $kernel = $this->getApplication()->getKernel(); - if (!$kernel->isDebug() || !(new ConfigCache($kernel->getContainer()->getParameter('debug.container.dump'), true))->isFresh()) { $buildContainer = \Closure::bind(function () { return $this->buildContainer(); }, $kernel, \get_class($kernel)); $container = $buildContainer(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php index 9a27604742..0730c87ae5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php @@ -108,7 +108,7 @@ EOF if ($extension instanceof ConfigurationInterface) { $configuration = $extension; } else { - $configuration = $extension->getConfiguration([], $this->getContainerBuilder()); + $configuration = $extension->getConfiguration([], $this->getContainerBuilder($this->getApplication()->getKernel())); } $this->validateConfiguration($extension, $configuration); diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php index 60db01fd9f..660bf3f96a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php @@ -123,7 +123,8 @@ EOF $errorIo = $io->getErrorStyle(); $this->validateInput($input); - $object = $this->getContainerBuilder(); + $kernel = $this->getApplication()->getKernel(); + $object = $this->getContainerBuilder($kernel); if ($input->getOption('env-vars')) { $options = ['env-vars' => true]; @@ -160,12 +161,12 @@ EOF $options['show_hidden'] = $input->getOption('show-hidden'); $options['raw_text'] = $input->getOption('raw'); $options['output'] = $io; - $options['is_debug'] = $this->getApplication()->getKernel()->isDebug(); + $options['is_debug'] = $kernel->isDebug(); try { $helper->describe($io, $object, $options); - if (isset($options['id']) && isset($this->getApplication()->getKernel()->getContainer()->getRemovedIds()[$options['id']])) { + if (isset($options['id']) && isset($kernel->getContainer()->getRemovedIds()[$options['id']])) { $errorIo->note(sprintf('The "%s" service or alias has been removed or inlined when the container was compiled.', $options['id'])); } } catch (ServiceNotFoundException $e) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php index a07c5d00ff..d7e086e043 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php @@ -76,7 +76,7 @@ EOF $io = new SymfonyStyle($input, $output); $errorIo = $io->getErrorStyle(); - $builder = $this->getContainerBuilder(); + $builder = $this->getContainerBuilder($this->getApplication()->getKernel()); $serviceIds = $builder->getServiceIds(); $serviceIds = array_filter($serviceIds, [$this, 'filterToServiceTypes']); @@ -155,7 +155,7 @@ EOF private function getFileLink(string $class): string { if (null === $this->fileLinkFormatter - || (null === $r = $this->getContainerBuilder()->getReflectionClass($class, false))) { + || (null === $r = $this->getContainerBuilder($this->getApplication()->getKernel())->getReflectionClass($class, false))) { return ''; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php index 6a849fcd65..1ae5835447 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php @@ -82,7 +82,12 @@ EOF $name = $input->getArgument('name'); $helper = new DescriptorHelper($this->fileLinkFormatter); $routes = $this->router->getRouteCollection(); - $container = $this->fileLinkFormatter ? \Closure::fromCallable([$this, 'getContainerBuilder']) : null; + $container = null; + if ($this->fileLinkFormatter) { + $container = function () { + return $this->getContainerBuilder($this->getApplication()->getKernel()); + }; + } if ($name) { if (!($route = $routes->get($name)) && $matchingRoutes = $this->findRouteNameContaining($name, $routes)) {