我可以定义事件侦听器/订阅者在原则中调用的顺序吗? [英] Can I define the order in which event listeners / subscribers are called in doctrine?
本文介绍了我可以定义事件侦听器/订阅者在原则中调用的顺序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
onFlush
事件。 我想确保 a :: onFlush()
始终在之前调用B :: onFlush()
。
我在文档中找不到任何资源。
我使用symfony2,所以如果我可以传递值在服务定义。
解决方案
为您的服务标签添加优先级。
服务:
my.listener:
class: Acme\SearchBundle\EventListener\SearchIndexer
标签:
- {name:doctrine.event_listener,event:postPersist,priority:100}
I have two event subscribers A and B. Both subscribed to the onFlush
event.
I want to make sure that a::onFlush()
is always called before B::onFlush()
.
I can't find any resource on this in the documentation.
I use symfony2 so it would be great if I could just pass the value in in the service definition.
解决方案
Add a priority to your service tag. The higher the priority the earlier it will run.
services:
my.listener:
class: Acme\SearchBundle\EventListener\SearchIndexer
tags:
- { name: doctrine.event_listener, event: postPersist, priority: 100 }
这篇关于我可以定义事件侦听器/订阅者在原则中调用的顺序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文