Layke
Layke

Reputation: 53136

Allow custom bundle to add it's own config setting for another bundle (Doctrine)

I have a custom Bundle, let's call it FooBarBundle.

Now, from within a custom Extension, I would like to prepend the following:

# Doctrine Configuration
doctrine:
    orm:
        mappings:
            FooBarBundle : ~

I'm under the belief that this shouldn't be possible, but I can't find any confirmation that one bundle cannot prepend configuration options of another Bundle.

I'm not sure if this is related: http://symfony.com/doc/current/bundles/prepend_extension.html

Ideally, I would like a bunch of my own bundles to add their own Doctrine Mappings rather than rely on updating the Config.yml when using each Bundle.

Upvotes: 2

Views: 664

Answers (1)

yceruto
yceruto

Reputation: 9575

Yes, you can do this for each bundle without to update the config.yml file:

namespace FooBarBundle\DependencyInjection;

// ...

class FooBarExtension extends Extension implements PrependExtensionInterface
{
    //...

    public function prepend(ContainerBuilder $container)
    {
        $container->loadFromExtension('doctrine', array(
            'orm' => array(
                'mappings' => array(
                     'FooBarBundle' => null,
                )
            ),
        ));
    }
}

If you have many bundles each config will be merged.

Upvotes: 2

Related Questions