Answer the question
In order to leave comments, you need to log in
What is the correct way to create an EventSubscriber?
Let's say I have an Employee entity. And in the controller, when a new employee is created, I dispatch an event
$this->eventDispatcher(new EmployeeCreatedEvent());
Answer the question
In order to leave comments, you need to log in
By using expressions from the abbreviation CRUD in the names of business logic events, I will assume that the application is relatively simple, and events will not be reused. If you are not going to hang several handlers on this event, then I recommend not to complicate it and just make sure that the logic of the controller, sending messages and storing templates is separated from each other.
An example of using the subscription system in Symfony can be seen in the validation system. There is just the reuse of events in their own system, and the points to which you can connect with custom code.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question