8000 bug #53582 [TwigBundle] Fix configuration when "paths" is null (smnan… · symfony/symfony@c7bafc2 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit c7bafc2

Browse files
committed
bug #53582 [TwigBundle] Fix configuration when "paths" is null (smnandre)
This PR was merged into the 5.4 branch. Discussion ---------- [TwigBundle] Fix configuration when "paths" is null | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | .. | License | MIT TwigBundle configuration throws an error when paths config is empty (found it while commenting a line) ```yaml twig: default_path: '%kernel.project_dir%/templates' form_themes: - 'form/form_theme.html.twig' paths: # '%kernel.project_dir%/templates/foo': Bar ``` ```console In Configuration.php line 159: [ErrorException] Warning: foreach() argument must be of type array|object, null given Exception trace: ``` Triggered by this line ```diff ->arrayNode('paths') ->normalizeKeys(false) ->useAttributeAsKey('paths') ->beforeNormalization() ->always() ->then(function ($paths) { $normalized = []; - foreach ($paths as $path => $namespace) { if (\is_array($namespace)) { // xml $path = $namespace['value']; $namespace = $namespace['namespace']; } ``` This PR replace `always` with `isArray` and add a test Commits ------- c72236b [TwigBundle] Fix configuration when 'paths' is null
2 parents 47685ff + c72236b commit c7bafc2

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private function addTwigOptions(ArrayNodeDefinition $rootNode)
147147
->normalizeKeys(false)
148148
->useAttributeAsKey('paths')
149149
->beforeNormalization()
150-
->always()
150+
->ifArray()
151151
->then(function ($paths) {
152152
$normalized = [];
153153
foreach ($paths as $path => $namespace) {

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/ConfigurationTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,16 @@ public function testArrayKeysInGlobalsAreNotNormalized()
5252

5353
$this->assertSame(['global' => ['value' => ['some-key' => 'some-value']]], $config['globals']);
5454
}
55+
56+
public function testNullPathsAreConvertedToIterable()
57+
{
58+
$input = [
59+
'paths' => null,
60+
];
61+
62+
$processor = new Processor();
63+
$config = $processor->processConfiguration(new Configuration(), [$input]);
64+
65+
$this->assertSame([], $config['paths']);
66+
}
5567
}

0 commit comments

Comments
 (0)
0