我有app/config.yml
这个:
# Doctrine Configuration
doctrine:
dbal:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
现在我创建了我的包,我希望它覆盖一些配置:
doctrine:
orm:
resolve_target_entities:
Acme\UserBundle\Interfaces\User: Acme\MyBundle\Entity\User
我想在不更改app/config.yml
答案 0 :(得分:3)
我通过添加编译器传递找到了解决方案:
class OrmResolverCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config'));
$loader->load('orm.yml');
$def = $container->findDefinition('doctrine.orm.listeners.resolve_target_entity');
foreach ($container->getParameter('resolve_target_entities') as $name => $implementation) {
$def->addMethodCall('addResolveTargetEntity', array( $name, $implementation, array() ));
}
$def->addTag('doctrine.event_listener', array('event' => 'loadClassMetadata'));
}
}
我们还需要在Bundle内的orm.yml
目录中创建Resources/config
。
最后在controllerBundle类中注册编译器传递:
class MyAcmeBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new OrmResolverCompilerPass());
}
}
答案 1 :(得分:2)
您现在可以使用PrependExtensionInterface
:
class ThirisCartLogicCatalogExtension extends Extension implements PrependExtensionInterface
{
public function prepend(ContainerBuilder $container)
{
$config = Yaml::parse(file_get_contents(__DIR__.'/../Resources/config/config.yml'));
foreach ($config as $key => $configuration) {
$container->prependExtensionConfig($key, $configuration);
}
}
}
使用此代码,您的捆绑包中的config.yml将无条件地合并到全局配置中。
请注意,您以这种方式加载is not validated for syntax的配置文件。