[FrameworkBundle] Add argument KernelInterface to BuildDebugContainerTrait::getContainerBuilder()

This commit is contained in:
Nyholm 2021-04-13 22:49:27 +02:00 committed by Oskar Stark
parent cc29772236
commit 0e9652a4bc
6 changed files with 18 additions and 12 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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);

View File

@ -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) {

View File

@ -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 '';
}

View File

@ -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)) {