8000 [FrameworkBundle] Allow disabling dumping of container to XML to improve performance by ruudk · Pull Request #49487 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Allow disabling dumping of container to XML to improve performance #49487

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

Merged
merged 1 commit into from
Feb 22, 2023
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
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ CHANGELOG
* Allow setting private services with the test container
* Register alias for argument for workflow services with workflow name only
* Configure the `ErrorHandler` on `FrameworkBundle::boot()`
* Allow setting `debug.container.dump` to `false` to disable dumping the container to XML

6.2
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function getContainerBuilder(KernelInterface $kernel): ContainerBuilde
return $this->containerBuilder;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private function getContainerBuilder(): ContainerBuilder
$kernel = $this->getApplication()->getKernel();
$kernelContainer = $kernel->getContainer();

if (!$kernel->isDebug() || !(new ConfigCache($kernelContainer->getParameter('debug.container.dump'), true))->isFresh()) {
if (!$kernel->isDebug() || !$kernelContainer->getParameter('debug.container.dump') || !(new ConfigCache($kernelContainer->getParameter('debug.container.dump'), true))->isFresh()) {
if (!$kernel instanceof Kernel) {
throw new RuntimeException(sprintf('This command does not support the application kernel: "%s" does not extend "%s".', get_debug_type($kernel), Kernel::class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ private function getContainerEnvVars(ContainerBuilder $container): array
return [];
}

if (!is_file($container->getParameter('debug.container.dump'))) {
if (!$container->getParameter('debug.container.dump') || !is_file($container->getParameter('debug.container.dump'))) {
return [];
}

Expand Down
8000
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class ContainerBuilderDebugDumpPass implements CompilerPassInterface
*/
public function process(ContainerBuilder $container)
{
if (!$container->getParameter('debug.container.dump')) {
return;
}

$cache = new ConfigCache($container->getParameter('debug.container.dump'), true);
if (!$cache->isFresh()) {
$cache->write((new XmlDumper($container))->dump(), $container->getResources());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ private function registerDebugConfiguration(array $config, ContainerBuilder $con

$debug = $container->getParameter('kernel.debug');

if ($debug) {
if ($debug && !$container->hasParameter('debug.container.dump')) {
$container->setParameter('debug.container.dump', '%kernel.build_dir%/%kernel.container_class%.xml');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ public function testNoDebug()
$this->assertStringContainsString('public', $tester->getDisplay());
}

public function testNoDumpedXML()
{
static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml', 'debug' => true, 'debug.container.dump' => false]);

$application = new Application(static::$kernel);
$application->setAutoExit(false);

$tester = new ApplicationTester($application);
$tester->run(['command' => 'debug:container']);

$this->assertStringContainsString('public', $tester->getDisplay());
}

public function testPrivateAlias()
{
static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml']);
Expand Down
0