0

Assume I have an event called XXX and two different complex subscribers, that can look like this:

class SubscriberOneXXX extends EventSubscriber {
    function actionWithPriority1() { ... }
    function actionWithPriority2() { ... }
    function actionWithPriority3() { ... }
}

And the second one:

class SubscriberTwoXXX extends EventSubscriber {
    function actionWithPriority1() { ... }
    function actionWithPriority2() { ... }
    function actionWithPriority3() { ... }
}

We may assume that these two subscribers represent different workflows of parallel processes and are independent.

How can I stop event propagation in SubscriberOneXXX and skip remained actions, but allow other subscribers to process the event?

AndrewShmig
  • 4,843
  • 6
  • 39
  • 68
  • I'm not sure you can, the goal of the stop propagation is stop the event, so the others subscribers aren't run. You could add a boolean flag inside your subscriber that your change when you want. And check the flag before executing of your logic. – Mcsky May 24 '18 at 10:19
  • Make yourself a sub-event. SubscriberOne would just send an SubscriberOne sub-event. Your s1 three actions would just be listeners to this event and if one of them stops propagation then oh well. Repeat for your second subscriber. Needless to say, make sure you really need this functionality before implementing it. The flag idea is probably a better approach. – Cerad May 24 '18 at 13:09
  • 1
    It migth be a complex implementation but [semaphores](http://php.net/manual/es/book.sem.php) should solve your problem, here is an [explanation](https://stackoverflow.com/questions/39976805/how-to-properly-use-php5-semaphores) also you could use the [symfony lock component](https://symfony.com/doc/3.4/components/lock.html) – Juan I. Morales Pestana May 25 '18 at 12:48

0 Answers0