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.
When an event is raised, the subscriber methods are run one at a time in no particular order. You can't specify the order in which the subscriber methods are called. You create an event subscriber method just like other methods except that you specify properties that set up the subscription to an event publisher.
Doctrine event subscribers cannot return a flexible array of methods to call for the events like the Symfony event subscribercan. Doctrine event subscribers must return a simple array of the event names they subscribe to.
Subscribing to an event tells the runtime that the subscriber method must be called whenever the publisher method is run, either by code (as with business and integration events) or by the system (as with trigger events).
When the published event is raised, the event subscriber is called and its code is run. Subscribing to an event tells the runtime that the subscriber method must be called whenever the publisher method is run, either by code (as with business and integration events) or by the system (as with trigger events).
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 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With