Skip to content

Commit

Permalink
IBX-88: Overridden Symfony debug:config command to use custom Contain…
Browse files Browse the repository at this point in the history
…erBuilder
  • Loading branch information
alongosz committed Nov 25, 2021
1 parent 4b0be87 commit 2f10239
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/bundle/Command/BuildDebugContainerTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Bundle\CompatibilityLayer\Command;

use Ibexa\Bundle\CompatibilityLayer\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
use Symfony\Component\DependencyInjection\ContainerBuilder as SymfonyContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\KernelInterface;

/**
* @internal
*
* @see \Symfony\Bundle\FrameworkBundle\Command\BuildDebugContainerTrait
*/
trait BuildDebugContainerTrait
{
protected $containerBuilder;

/**
* Loads the ContainerBuilder from the cache.
*
* @throws \LogicException|\Exception
*/
protected function getContainerBuilder(KernelInterface $kernel): SymfonyContainerBuilder
{
if ($this->containerBuilder) {
return $this->containerBuilder;
}

if (!$kernel->isDebug() || !(new ConfigCache($kernel->getContainer()->getParameter('debug.container.dump'), true))->isFresh()) {
$buildContainer = \Closure::bind(function () {
$this->initializeBundles();

return $this->buildContainer();
}, $kernel, \get_class($kernel));
$container = $buildContainer();
$container->getCompilerPassConfig()->setRemovingPasses([]);
$container->getCompilerPassConfig()->setAfterRemovingPasses([]);
$container->compile();
} else {
(new XmlFileLoader($container = new ContainerBuilder(), new FileLocator()))->load($kernel->getContainer()->getParameter('debug.container.dump'));
$locatorPass = new ServiceLocatorTagPass();
$locatorPass->process($container);
}

return $this->containerBuilder = $container;
}
}
21 changes: 21 additions & 0 deletions src/bundle/Command/SymfonyConfigDebugCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Bundle\CompatibilityLayer\Command;

use Symfony\Bundle\FrameworkBundle\Command\ConfigDebugCommand;

/**
* @see \Symfony\Bundle\FrameworkBundle\Command\ConfigDebugCommand
*/
class SymfonyConfigDebugCommand extends ConfigDebugCommand
{
use BuildDebugContainerTrait;

protected static $defaultName = 'debug:config';
}
2 changes: 2 additions & 0 deletions src/bundle/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ services:
decorates: 'event_dispatcher'
arguments:
$innerEventDispatcher: '@.inner'

Ibexa\Bundle\CompatibilityLayer\Command\SymfonyConfigDebugCommand: ~

0 comments on commit 2f10239

Please sign in to comment.