Symfony编译器传递:添加条令筛选器时出错
我想在我创建的包中添加一个带有Symfony编译器传递:添加条令筛选器时出错,symfony,Symfony,我想在我创建的包中添加一个带有CompilerPass的条令过滤器 我尝试了这个方法,我认为过滤器被添加了(因为我在FilterCollection中调用了dump():enable()函数被调用) 但现在,我有一个错误: 传递给条令\Bundle\DoctrineBundle\managerConfiguration::configure()的参数1必须实现接口条令\ORM\EntityManagerInterface,给定条令\ORM\Query\FilterCollection的实例 我认
CompilerPass
的条令过滤器
我尝试了这个方法,我认为过滤器被添加了(因为我在FilterCollection
中调用了dump():enable()
函数被调用)
但现在,我有一个错误:
传递给条令\Bundle\DoctrineBundle\managerConfiguration::configure()的参数1必须实现接口条令\ORM\EntityManagerInterface,给定条令\ORM\Query\FilterCollection的实例
我认为,
->addMethodCall('getFilters',[],true)
取代了doctor.orm.default\u entity\u manager
服务的原始类。您知道如何避免这种行为吗?addMethodCall上的第三个参数指示DI编译器使用调用的返回值作为该点的服务实例
从方法的签名中可以看到:
addMethodCall(字符串$method,数组$arguments=[],bool$returnsClone=false)
其中,第三个参数明确记录为“调用是否返回服务实例”
如果必须在FilterCollection上调用enable
方法,则必须修饰configurator服务并从那里调用enable
方法
class UserCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
$container->getDefinition('doctrine.orm.default_configuration')
->addMethodCall('addFilter', [
'deleted_at',
DeletedAtFilter::class,
])
;
$container->getDefinition('doctrine.orm.default_entity_manager')
->addMethodCall('getFilters', [], true)
->addMethodCall('enable', [
'deleted_at',
])
;