Skip to content
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

The configuration of packages in the application is ignored after they are applied inside prependExtension the bundle #54840

Closed
tebaly opened this issue May 4, 2024 · 4 comments

Comments

@tebaly
Copy link

tebaly commented May 4, 2024

Symfony version(s) affected

6.4,7

Description

use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;

class SomeBundle extends AbstractBundle
{
// ...
    public function prependExtension(ContainerConfigurator $container, ContainerBuilder $builder): void
    {
        $container->import('../config/packages/vich_uploader.yaml');

After this, any changes to the root of the application in which the bundle is installed are ignored. Although it is declared that the settings in ../config/packages in the application should overwrite all changes made by the bundle.

After commenting the lines $container->import('. inside the bundle, the application settings are made as expected

How to reproduce

Combine public function prependExtension and $container->import('../config/packages/...);

Possible Solution

No response

Additional Context

Perhaps this is related specifically to vich_uploader

@xabbuh
Copy link
Member

xabbuh commented May 4, 2024

Can you create a small example application that allows to reproduce your issue?

@yceruto
Copy link
Member

yceruto commented May 4, 2024

I confirm this issue, and the reason is that $container->import() appends the config instead of prepending it, making it the preferred config in the stack, even over the app config (which is loaded earlier).

That's why we recently discouraged using $container->import() in prependExtension symfony/symfony-docs#19739.

But don't be sad 😄, you can use it starting with Symfony 7.1 #52843. Meanwhile, for previous Symfony versions, I've backported that feature into this package https://github.com/yceruto/micro-symfony, which fixes this issue. Otherwise, you can always use $builder->prependExtensionConfig() instead, with the actual limitations.

Related to #52789

Closing as this is an expected limitation prior to 7.1 and fixed in 7.1. Thanks for reporting!

@yceruto yceruto closed this as completed May 4, 2024
@tebaly
Copy link
Author

tebaly commented May 5, 2024

you can always use $builder->prependExtensionConfig() instead

@yceruto @xabbuh It seems to me that this method is also a bug. When trying to add a field that is not yet in the application configuration file (../configs/liip_imagine.yaml), it produces an error like

Warning: Undefined array key "resolvers"

    public function prependExtension(ContainerConfigurator $container, ContainerBuilder $builder): void
    {
        $builder->prependExtensionConfig('liip_imagine', [
            'resolvers' => //...

../configs/liip_imagine.yaml

liip_imagine: ~

@xabbuh
Copy link
Member

xabbuh commented May 5, 2024

Can you create a small example application that allows to reproduce your issue?

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