I'm using Symfony 4 and there are custom event and subscriber, e.g. CustomEvent and CustomEventSubscriber. There is module which dispatch CustomEvent, e.g. CustomModule. And that module is using in the controller (ControllerA) and command (CommandB).
In other words possible two follow scenarios:
ControllerA -> CustomModule -> CustomEventSubscriber(CustomEvent)
Or
CommandB -> CustomModule -> CustomEventSubscriber(CustomEvent)
Logic in the CustomEventSubscriber little bit different depends on where was called CustomModule (ControllerA or CommandB).
How to pass that information to the CustomEventSubscriber
?
I can add $context
property to the CustomEvent
and set it in the CustomModule
. But in that case I should pass info about context to the CustomModule
.
Or maybe I can use some global settings, e.g. container?
Or create two different event subscribers per CustomEvent, disable auto-wiring, and 'manually' init and add to the dispatcher in ControllerA and CommandB?