Skip to content

Commit 5b81013

Browse files
Merge branch '5.4' into 6.0
* 5.4: Fix merge [Mime] Throw exception when body in Email attach method is not ok [VarDumper][VarExporter] Deal with DatePeriod->include_end_date on PHP 8.2 [Cache] Throw when "redis_sentinel" is used with a non-Predis "class" option fix merge Bootstrap 4 fieldset for row errors [Form] Fix same choice loader with different choice values [Filesystem] Safeguard (sym)link calls Fix dumping extension config without bundle [HttpClient] Honor "max_duration" when replacing requests with async decorators [HttpClient] Add missing HttpOptions::setMaxDuration() [HttpFoundation] [Session] Overwrite invalid session id
2 parents c66de05 + 7c1a49a commit 5b81013

File tree

7 files changed

+79
-17
lines changed

7 files changed

+79
-17
lines changed

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\ConfigurationExtensionInterface;
2021
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
2122

@@ -54,7 +55,7 @@ protected function listBundles(OutputInterface|StyleInterface $output)
5455
}
5556
}
5657

57-
protected function findExtension(string $name): ExtensionInterface
58+
protected function findExtension(string $name, ContainerBuilder $container): ExtensionInterface
5859
{
5960
$bundles = $this->initializeBundles();
6061
$minScore = \INF;
@@ -90,20 +91,18 @@ protected function findExtension(string $name): ExtensionInterface
9091
$guess = $bundle->getName();
9192
$minScore = $distance;
9293
}
94+
}
9395

94-
$extension = $bundle->getContainerExtension();
95-
96-
if ($extension) {
97-
if ($name === $extension->getAlias()) {
98-
return $extension;
99-
}
96+
if ($container->hasExtension($name)) {
97+
return $container->getExtension($name);
98+
}
10099

101-
$distance = levenshtein($name, $extension->getAlias());
100+
foreach ($container->getExtensions() as $extension) {
101+
$distance = levenshtein($name, $extension->getAlias());
102102

103-
if ($distance < $minScore) {
104-
$guess = $extension->getAlias();
105-
$minScore = $distance;
106-
}
103+
if ($distance < $minScore) {
104+
$guess = $extension->getAlias();
105+
$minScore = $distance;
107106
}
108107
}
109108

Command/ConfigDebugCommand.php

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

93-
$extension = $this->findExtension($name);
94-
$extensionAlias = $extension->getAlias();
9593
$container = $this->compileContainer();
94+
$extension = $this->findExtension($name, $container);
95+
$extensionAlias = $extension->getAlias();
9696

9797
$config = $this->getConfig($extension, $container);
9898

@@ -193,7 +193,8 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
193193

194194
if ($input->mustSuggestArgumentValuesFor('path') && null !== $name = $input->getArgument('name')) {
195195
try {
196-
$config = $this->getConfig($this->findExtension($name), $this->compileContainer());
196+
$container = $this->compileContainer();
197+
$config = $this->getConfig($this->findExtension($name, $container), $container);
197198
$paths = array_keys(self::buildPathsCompletion($config));
198199
$suggestions->suggestValues($paths);
199200
} catch (LogicException $e) {

Command/ConfigDumpReferenceCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
103103
return 0;
104104
}
105105

106-
$extension = $this->findExtension($name);
106+
$container = $this->getContainerBuilder($this->getApplication()->getKernel());
107+
$extension = $this->findExtension($name, $container);
107108

108109
if ($extension instanceof ConfigurationInterface) {
109110
$configuration = $extension;
110111
} else {
111-
$configuration = $extension->getConfiguration([], $this->getContainerBuilder($this->getApplication()->getKernel()));
112+
$configuration = $extension->getConfiguration([], $container);
112113
}
113114

114115
$this->validateConfiguration($extension, $configuration);

Tests/Functional/ConfigDebugCommandTest.php

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

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

Tests/Functional/ConfigDumpReferenceCommandTest.php

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

53+
public function testDumpExtensionConfigWithoutBundle()
54+
{
55+
$tester = $this->createCommandTester();
56+
$ret = $tester->execute(['name' => 'test_dump']);
57+
58+
$this->assertSame(0, $ret, 'Returns 0 in case of success');
59+
$this->assertStringContainsString('enabled: true', $tester->getDisplay());
60+
}
61+
5362
public function testDumpAtPath()
5463
{
5564
$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+
}

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\Definition\Builder\TreeBuilder;
1617
use Symfony\Component\Config\Definition\ConfigurationInterface;
1718
use Symfony\Component\Config\Loader\LoaderInterface;
@@ -80,6 +81,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
8081
protected function build(ContainerBuilder $container)
8182
{
8283
$container->register('logger', NullLogger::class);
84+
$container->registerExtension(new TestDumpExtension());
8385
}
8486

8587
public function __sleep(): array

0 commit comments

Comments
 (0)