Answer the question
In order to leave comments, you need to log in
Is it good practice to bind to Doctrine events?
Good afternoon!
Ripe question. For example, there is a task to create logs (or send emails) at the time of creating the User entity. We decide to implement this through events. There are two options:
1) Listen to Doctrine:prePersist and call the appropriate service.
2) Create your own event:
$this->userRepository->save($user);
$this->eventDispatcher->dispatch(SomeEvent::EVENT, new UserEvent($user));
Answer the question
In order to leave comments, you need to log in
For such purposes, it is better to use events. Better yet, domain-event.
Example here: https://github.com/fesor/domain-events
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question