8000 Fix dumping extension config without bundle · symfony/symfony@42fa0cb · GitHub
[go: up one dir, main page]

Skip to content

Commit 42fa0cb

Browse files
committed
Fix dumping extension config without bundle
1 parent 1a7fa5d commit 42fa0cb

File tree

7 files changed

+77
-16
lines changed

7 files changed

+77
-16
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Helper\Table;
1717
use Symfony\Component\Console\Output\OutputInterface;
1818
use Symfony\Component\Console\Style\StyleInterface;
19+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1920
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
2021

2122
/**
@@ -59,7 +60,7 @@ protected function listBundles($output)
5960
/**
6061
* @return ExtensionInterface
6162
*/
62-
protected function findExtension($name)
63+
protected function findExtension($name, ContainerBuilder $container)
6364
{
6465
$bundles = $this->initializeBundles();
6566
$minScore = \INF;
@@ -79,20 +80,18 @@ protected function findExtension($name)
7980
$guess = $bundle->getName();
8081
$minScore = $distance;
8182
}
83+
}
8284

83-
$extension = $bundle->getContainerExtension();
84-
85-
if ($extension) {
86-
if ($name === $extension->getAlias()) {
87-
return $extension;
88-
}
85+
if ($container->hasExtension($name)) {
86+
return $container->getExtension($name);
87+
}
8988

90-
$distance = levenshtein($name, $extension->getAlias());
89+
foreach ($container->getExtensions() as $extension) {
90+
$distance = levenshtein($name, $extension->getAlias());
9191

92-
if ($distance < $minScore) {
93-
$guess = $extension->getAlias();
94-
$minScore = $distance;
95-
}
92+
if ($distance < $minScore) {
93+
$guess = $extension->getAlias();
94+
$minScore = $distance;
9695
}
9796
}
9897

src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7979
return 0;
8080
}
8181

82-
$extension = $this->findExtension($name);
83-
$extensionAlias = $extension->getAlias();
8482
$container = $this->compileContainer();
83+
$extension = $this->findExtension($name, $container);
84+
$extensionAlias = $extension->getAlias();
8585

8686
$config = $container->resolveEnvPlaceholders(
8787
$container->getParameterBag()->resolveValue(

src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8989
return 0;
9090
}
9191

92-
$extension = $this->findExtension($name);
92+
$container = $this->getContainerBuilder();
93+
$extension = $this->findExtension($name, $container);
9394

94-
$configuration = $extension->getConfiguration([], $this->getContainerBuilder());
95+
$configuration = $extension->getConfiguration([], $container);
9596

9697
$this->validateConfiguration($extension, $configuration);
9798

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ public function testDefaultParameterValueIsResolvedIfConfigIsExisting()
6868
$this->assertStringContainsString(sprintf("dsn: 'file:%s/profiler'", $kernelCacheDir), $tester->getDisplay());
6969
}
7070

71+
public function testDumpExtensionConfigWithoutBundle()
72+
{
73+
$tester = $this->createCommandTester();
74+
$ret = $tester->execute(['name' => 'test_dump']);
75+
76+
$this->assertSame(0, $ret, 'Returns 0 in case of success');
77+
$this->assertStringContainsString('enabled: true', $tester->getDisplay());
78+
}
79+
7180
public function testDumpUndefinedBundleOption()
7281
{
7382
$tester = $this->createCommandTester();

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDumpReferenceCommandTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ public function testDumpBundleName()
4040
$this->assertStringContainsString(' custom:', $tester->getDisplay());
4141
}
4242

43+
public function testDumpExtensionConfigWithoutBundle()
44+
{
45+
$tester = $this->createCommandTester();
46+
$ret = $tester->execute(['name' => 'test_dump']);
47+
48+
$this->assertSame(0, $ret, 'Returns 0 in case of success');
49+
$this->assertStringContainsString('enabled: true', $tester->getDisplay());
50+
}
51+
4352
public function testDumpAtPath()
4453
{
4554
$tester = $this->createCommandTester();
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Extension;
13+
14+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15+
use Symfony\Component\Config\Definition\ConfigurationInterface;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\Component\DependencyInjection\Extension\Extension;
18+
19+
class TestDumpExtension extends Extension implements ConfigurationInterface
20+
{
21+
public function getConfigTreeBuilder()
22+
{
23+
$treeBuilder = new TreeBuilder('test_dump');
24+
$treeBuilder->getRootNode()
25+
->children()
26+
->booleanNode('enabled')->defaultTrue()->end()
27+
->end()
28+
;
29+
30+
return $treeBuilder;
31+
}
32+
33+
public function load(array $configs, ContainerBuilder $container)
34+
{
35+
}
36+
37+
public function getConfiguration(array $config, ContainerBuilder $container)
38+
{
39+
return $this;
40+
}
41+
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\app;
1313

1414
use Psr\Log\NullLogger;
15+
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Extension\TestDumpExtension;
1516
use Symfony\Component\Config\Loader\LoaderInterface;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -78,6 +79,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
7879
protected function build(ContainerBuilder $container)
7980
{
8081
$container->register('logger', NullLogger::class);
82+
$container->registerExtension(new TestDumpExtension());
8183
}
8284

8385
public function __sleep(): array

0 commit comments

Comments
 (0)
0