Skip to content

[DependencyInjection] Import config inside of a bundle does not work anymore #57936

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

Closed
pschombara opened this issue Aug 6, 2024 · 3 comments
Closed

Comments

@pschombara
Copy link

Symfony version(s) affected

7.1.0

Description

Since Symfony 7.1 prependExtension with $container->import ignores the passed configuration.

In documentation it is mentioned:

Starting from Symfony 7.1, calling the import() method inside prependExtension() will prepend the given configuration. In previous Symfony versions, this method appended the configuration.

But the configuration of the file is completely ignored.

As example we use a bundle to share configuration for the messenger component.

Part of output of bin/console debug:config framework with symfony/dependency-injection: ^7.1

    messenger:
        enabled: true
        routing: {  }
        serializer:
            default_serializer: messenger.transport.native_php_serializer
            symfony_serializer:
                format: json
                context: {  }
        transports: {  }

Part of output of bin/console debug:config framework with symfony/dependency-injection: <7.1

    messenger:
        serializer:
            default_serializer: messenger.transport.symfony_serializer
            symfony_serializer:
                format: json
                context: {  }
        transports:
            example:
                dsn: '%env(RABBITMQ_URL)%/%2f/messages'
                options:
                    exchange:
                        name: example.exchange
                        type: direct
                    queues:
                        example.queue:
                            binding_keys:
                                - example
                serializer: null
                failure_transport: null
                retry_strategy:
                    service: null
                    max_retries: 3
                    delay: 1000
                    multiplier: 2
                    max_delay: 0
                rate_limiter: null

How to reproduce

A bundle wich imports a PHP config file.

// src/ExampleBundle.php
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;

class ExampleBundle extends AbstractBundle
{
    public function prependExtension(ContainerConfigurator $container, ContainerBuilder $builder): void
    {
        $container->import('../config/packages/messenger.php');
    }

Example config file:

// config/packages/messenger.php
return static function (FrameworkConfig $framework, ContainerConfigurator $container): void {
    $messenger = $framework->messenger();

    $messenger
        ->transport('example')
        ->dsn(env('RABBITMQ_URL') . '/%2f/messages')
        ->options([
            'exchange' => [
                'name' => 'example.exchange',
                'type' => 'direct',
            ],
            'queues' => [
                'example.queue' => [
                    'binding_keys' => ['example']
                ],
            ],
        ])
    ;

Possible Solution

No response

Additional Context

No response

@pschombara pschombara added the Bug label Aug 6, 2024
@pschombara pschombara changed the title [DependencyInjection] Import config inside of bundle not working anymr [DependencyInjection] Import config inside of bundle not working anymore Aug 6, 2024
@pschombara pschombara changed the title [DependencyInjection] Import config inside of bundle not working anymore [DependencyInjection] Import config inside of a bundle does not work anymore Aug 6, 2024
@yceruto
Copy link
Member

yceruto commented Aug 6, 2024

I managed to reproduce it, on it already...

@yceruto
Copy link
Member

yceruto commented Aug 6, 2024

Could you please confirm that #57937 fixes the issue?

@pschombara
Copy link
Author

Yes it work again, thank you.

nicolas-grekas added a commit that referenced this issue Aug 7, 2024
…pend extension method (yceruto)

This PR was merged into the 7.1 branch.

Discussion
----------

[DependencyInjection] Fix importing PHP configs in the prepend extension method

| Q             | A
| ------------- | ---
| Branch?       | 7.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #57936
| License       | MIT

I missed this nesting case during #52843.

Commits
-------

94df570 Fix importing PHP config in prepend extension method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants