Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-88: Overridden debug:config command to use custom ContainerBuilder & restored ezplatform BC #4

Merged
merged 1 commit into from
Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: ~