I've been reading up a lot about the event driven architecture (EDA) design pattern, and while it appears exceptionally powerful (dare I saw beautiful?) I'm confused about two things: one, how to control conditional logic, and two, how to control exceptions.
Let's say I want to design some callback exposed for Ajax consumption. The callback will be fired by the front end with a "username" and "password", and I will return a localized "return code" indicating success or failure.
When a user successfully logs in, let's assume I log it, send management and email, and start a session. If I was using an EDA based pattern, I might have the following:
User Logs In -> (Dispatches event, always) -> (Log, Send Email, Start Session all called)
That is, the login callback will dispatch some notification issuing all registered classes listening to that particular event. My problem is, who is confirming if the authenticator pair (username, password) is successful? In some sense, these three events are only valid if the authentication was correct.
So, perhaps then I fire one event first, and only if successful, fire the others:
User Logs in -> (Dispatches event, always) -> Attempt to log in user (Dispatches event, if successful) -> (Log, Send Email, Start Session all called)
While that works, I have lost control of how to obtain feedback. Events appear to follow the "set and forget" train of thought; how can I return a code to the front end? That is, I cannot see a way for an event observer to give feedback to the subject.
This continues to exception handling; how is the best way to handle exceptions in this scenario?
Appreciate any advice! Adrian
(While it probably doesn't matter in a theoretical sense, I'm attempting to apply this to PHP)