Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to control Doctrine Event subscriber priorities

I have an entity which I have two separate event subscribers listen to postPersist and postUpdate events to trigger particular actions. In the EventDispatcher component in Symfony the listeners could have priority attached to them but I do not seem to find the priority option for Doctrine events. Is there a way to have the subscribers prioritized or Doctrine event dispatcher doesn't support it, I really can't seem to find the right option for that.

like image 480
Svetlin Staev Avatar asked Oct 27 '25 06:10

Svetlin Staev


2 Answers

Define your event listeners as a service and then you can set priority.

E.g. from this answer.

Can I define the order in which event listeners / subscribers are called in doctrine?

like image 83
Richard Avatar answered Oct 29 '25 05:10

Richard


If you are trying to specify the priority inside getSubscribedEvents() you should try with ['eventName' => ['methodName', $priority]]

like image 28
Vlad MN Avatar answered Oct 29 '25 07:10

Vlad MN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!