Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c7bafc2

Browse filesBrowse 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
Copy full SHA for c7bafc2

File tree

2 files changed

+13
-1
lines changed
Filter options

2 files changed

+13
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php
+1-1Lines changed: 1 addition & 1 deletion
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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/ConfigurationTest.php
+12Lines changed: 12 additions & 0 deletions
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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.