What if there are two ways to authenticate on your application, Login and password | JWT ? you would have to duplicate the code. With a single event you fixes the problem.
In addition, give you the possibility of more flexibility without modifying the core of your code.
Comment hidden by post author - thread only visible in this permalink
If I have two ways to authenticate I would separate the use-case specific logic into different (application) services and the shared logic into a domain service class.
Comment hidden by post author
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
For which use-cases could this event dispatcher be used?
Do you have some real-world examples?
Consider the real-world example where you want dispatch event when a user login
The event listener will be executed to set last connexion date :
$user->setLastLogin(new \DateTime());
$user->save();
Thanks for your answer. Why should I store the user's last login date with an event dispatcher when I could do the same without events?
What if there are two ways to authenticate on your application, Login and password | JWT ? you would have to duplicate the code. With a single event you fixes the problem.
In addition, give you the possibility of more flexibility without modifying the core of your code.
If I have two ways to authenticate I would separate the use-case specific logic into different (application) services and the shared logic into a domain service class.