Reputation: 23
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.
Upvotes: 2
Views: 2395
Reputation: 3135
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.
Upvotes: 3