gpt4 book ai didi

php - 在隔离包中注册 Symfony Hydrators

转载 作者:行者123 更新时间:2023-12-03 11:20:48 24 4
gpt4 key购买 nike

我创建了几个共享 Bundle 的模块化应用程序。其中一个包负责处理所有实体/存储库相关的逻辑(我们称之为 MyBundle)。

这个 MyBundle 包含几个自定义 Hydrator 。鉴于教义配置包含在特定应用程序中,并且我不希望在其 config.yml 文件中注册捆绑 Hydrator ,我如何在捆绑包中注册这些 Hydrator ?

我尝试在我的包中创建一个 CompilerPass,然后在学说 orm 配置服务上调用 addCustomHydrationMode 但这不起作用。

我还尝试创建一个“HydrationManager”类,注入(inject)实体管理器,然后在编译器传递中调用管理器上的 addHydrator 方法,该方法又调用 getConfiguration()->addCustomHydrationMode(...) 但这也不起作用

最佳答案

我正在寻找一个类似的解决方案,并偶然发现了这个例子:
https://github.com/vivait/user-bundle/blob/master/src/Vivait/UserBundle/DependencyInjection/DoctrineCompilerPass.php

<?php

namespace Vivait\UserBundle\DependencyInjection;

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

class DoctrineCompilerPass implements CompilerPassInterface
{
/**
* You can modify the container here before it is dumped to PHP code.
*
* @param ContainerBuilder $container
*
* @api
*/
public function process(ContainerBuilder $container)
{
$ormConfigDef = $container->getDefinition('doctrine.orm.configuration');
$ormConfigDef->addMethodCall(
'addCustomHydrationMode',
['UserCustomerHydrator', 'Vivait\UserBundle\Adapter\Hydrator\CustomerHydrator']
);
}
}

关于php - 在隔离包中注册 Symfony Hydrators,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37816618/

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