我想将Doctrine 捆绑包配置为具有DBAL连接。出于某种原因,配置需要一些逻辑来检索。我尝试使用容器扩展,然后在编译容器时使用编译器传递来执行逻辑,并将配置存储为容器参数。
在我的尝试过程中,我在Kernel类中注册了扩展和编译器通道,如下所示:
protected function build(ContainerBuilder $container)
{
// Those lines weren't there at the same time
$container->registerExtension(new MyCustomExtension());
$container->addCompilerPass(new MyCustomCompilerPass());
}
它似乎运行良好,因为我可以在控制台中看到我的参数:
# ./bin/console debug:container --parameters
Symfony Container Parameters
============================
------------------------------------------------------------- ------------------------------------------------------------------------
Parameter Value
------------------------------------------------------------- ------------------------------------------------------------------------
...
some.prefix.host some-mariadb-host
some.prefix.dbname some-database-name
...
问题是,当我尝试在我的中使用这些参数时,config/packages/doctrine.yaml
我的下一个控制台命令出现错误:
doctrine:
dbal:
driver: pdo_mysql
host: '%some.prefix.host%'
dbname: '%some.prefix.dbname%'
# ...
# ./bin/console debug:container --parameters
In ParameterBag.php line 98:
You have requested a non-existent parameter "some.prefix.host".
我正在使用Symfony 5.3和Doctrine bundle 2.4。
- 为什么我的参数对于 3rd 方捆绑配置似乎无法访问?
- 我怎样才能使这项工作?
- 有没有更好的方法来实现这一目标?