gpt4 book ai didi

Symfony 从 app/config.yml 覆盖配置

转载 作者:行者123 更新时间:2023-12-02 04:59:31 26 4
gpt4 key购买 nike

我的 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

的情况下添加此配置

最佳答案

我通过添加编译器 channel 找到了解决方案:

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 的 Resources/config 目录中创建 orm.yml

最后在 controllerBundle 类中注册编译器传递:

class MyAcmeBundle extends Bundle
{

public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new OrmResolverCompilerPass());
}

}

关于Symfony 从 app/config.yml 覆盖配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17338522/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com