Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit db59a7f

Browse files
committed
[Framework][debug:config] Allow to debug path with dot in key
1 parent b01d14a commit db59a7f

4 files changed

Lines changed: 46 additions & 2 deletions

File tree

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ protected function configure(): void
7272
7373
<info>php %command.full_name% framework serializer.enabled</info>
7474
75+
If a key in your path contains dots, surround it by brackets:
76+
77+
<info>php %command.full_name% extension "path.[sub.path].option"</info>
78+
7579
EOF
7680
)
7781
;
@@ -168,9 +172,14 @@ private function compileContainer(): ContainerBuilder
168172
*/
169173
private function getConfigForPath(array $config, string $path, string $alias): mixed
170174
{
171-
$steps = explode('.', $path);
175+
preg_match_all('/\[([^\]]+)\]|[^.]+/', $path, $matches);
176+
$steps = $matches[0];
172177

173178
foreach ($steps as $step) {
179+
if (str_starts_with($step, '[') && str_ends_with($step, ']')) {
180+
$step = substr($step, 1, -1);
181+
}
182+
174183
if (!\is_array($config) || !\array_key_exists($step, $config)) {
175184
throw new LogicException(\sprintf('Unable to find configuration for "%s.%s".', $alias, $path));
176185
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/DependencyInjection/Config/CustomConfig.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ public function addConfiguration($rootNode)
2222
->children()
2323
->scalarNode('child1')->end()
2424
->scalarNode('child2')->end()
25+
->end()
26+
->end()
27+
->arrayNode('options')
28+
->useAttributeAsKey('key')
29+
->arrayPrototype()
30+
->children()
31+
->scalarNode('key')->end()
32+
->scalarNode('data')->end()
2533
->end()
2634
->end()
2735
->end()

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/DependencyInjection/TestExtension.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ public function load(array $configs, ContainerBuilder $container): void
2929

3030
public function prepend(ContainerBuilder $container): void
3131
{
32-
$container->prependExtensionConfig('test', ['custom' => 'foo']);
32+
$container->prependExtensionConfig('test', [
33+
'custom' => 'foo',
34+
'options' => [
35+
'option.main' => ['data' => 'foo'],
36+
'option.sub' => ['data' => 'bar'],
37+
]
38+
]);
3339
}
3440

3541
public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,27 @@ public function testDumpBundleOption(bool $debug)
7878
$this->assertStringContainsString('foo', $tester->getDisplay());
7979
}
8080

81+
#[TestWith([true])]
82+
#[TestWith([false])]
83+
public function testDumpBundleOptionWithDotInKeyWithoutBracket(bool $debug)
84+
{
85+
$tester = $this->createCommandTester($debug);
86+
$ret = $tester->execute(['name' => 'TestBundle', 'path' => 'options.option.main']);
87+
$this->assertSame(1, $ret, 'Returns 0 in case of success');
88+
$this->assertStringContainsString('Unable to find configuration for "test.options.option.main"', $tester->getDisplay());
89+
}
90+
91+
#[TestWith([true])]
92+
#[TestWith([false])]
93+
public function testDumpBundleOptionWithDotInKeyWithBracket(bool $debug)
94+
{
95+
$tester = $this->createCommandTester($debug);
96+
$ret = $tester->execute(['name' => 'TestBundle', 'path' => 'options.[option.main]']);
97+
98+
$this->assertSame(0, $ret, 'Returns 0 in case of success');
99+
$this->assertStringContainsString('data: foo', $tester->getDisplay());
100+
}
101+
81102
#[TestWith([true])]
82103
#[TestWith([false])]
83104
public function testDumpWithoutTitleIsValidJson(bool $debug)

0 commit comments

Comments
 (0)