Skip to content

[TwigBundle] Fix configuration when "paths" is null #53582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 19, 2024

Conversation

smnandre
Copy link
Member

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)

twig:
    default_path: '%kernel.project_dir%/templates'

    form_themes:
        - 'form/form_theme.html.twig'

    paths:
        # '%kernel.project_dir%/templates/foo': Bar
In Configuration.php line 159:
                                                                        
  [ErrorException]                                                      
  Warning: foreach() argument must be of type array|object, null given                                                                         

Exception trace:

Triggered by this line

 ->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

@fabpot
Copy link
Member

fabpot commented Jan 19, 2024

Thank you @smnandre.

@fabpot fabpot merged commit c7bafc2 into symfony:5.4 Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants