2
votes

I'm building a bundle, which depends on another bundle. The parent bundle loads a services.yml file, which defines some parameters:

parameters:
    xbundle.doctrine.factory: Doctrine\ORM\Repository\DefaultRepositoryFactory
services:
    ....

I know the xbundle.doctrine.factory parameter can be changed from app/config/config.yml, but I want to change its value the from within my custom child bundle. I read the docs, and also the suggested stackoverflow questions, but still can't figure how to achieve it.

1
I don't have an example handy but I suspect you need a compiler pass: symfony.com/doc/current/cookbook/service_container/…. However, don't try to override the default doctrine repository factory unless you really really really know what you are doing. More than likely you can use doctrine event listeners. - Cerad

1 Answers

3
votes

You must write a CompilerPass in your child Bundle, and change the value:

// src/Acme/DemoBundle/DependencyInjection/Compiler/OverrideServiceCompilerPass.php
namespace Acme\DemoBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class OverrideServiceCompilerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {  
        $container->setParameter('xbundle.doctrine.factory', '..New Value ...');
    }
}

Some documentation here.