DEV Community


Discussion on: PHP - Create your own PHP PSR-14 event dispatcher

fadymr profile image
F.R Michel Author

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());

dopitz profile image
Daniel O.

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?

Thread Thread
fadymr profile image
F.R Michel Author • Edited

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.

Thread Thread

Some comments have been hidden by the post's author - find out more