Can I define the order in which event listeners /

2019-02-08 11:29发布

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.

1条回答
Evening l夕情丶
2楼-- · 2019-02-08 11:57

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 }
查看更多
登录 后发表回答