Skip to content

Instantly share code, notes, and snippets.

@harikt
Last active August 29, 2015 14:04
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harikt/905d7d68ac82b2c35295 to your computer and use it in GitHub Desktop.
Save harikt/905d7d68ac82b2c35295 to your computer and use it in GitHub Desktop.
When and where are you using an event / signal hanlder ?

Are you making use of the event handling system like Symfony event handler, Aura.Signal, Zend event manager or any other in your core framework?

Are you using signal/events before they hit the action class ( controller action ) ?

I have a feeling it will be good to have an event handling system in core of a framework.

The basic idea is to call a signal

  • before a route is checked
  • before dispatching
  • before sending the response

Currently I have one or two examples in mind,

  1. Caching the entire response before sending and on the next request before we check a route we can send the same response. But in the current world of Varnish, I am not sure it will be good to do so also.

  2. Before hitting a route, check whether the user is authenticated or not. Redirect to a different page, especially helpful when all the pages need authentication.

  3. Access seems good to have in action class having some sort of signal handler.

I would like to hear your use case for having an event handler in core of a framework in which your application is using it extensively that cannot be done other way.

Willing to share? Please comment below or send an email to my gmail account : kthari85

Thank you.

@koriym
Copy link

koriym commented Aug 6, 2014

In some of cases you described here (1, 2) I use AOP instead of event handler for BEAR.Sunday. Consumer and called method are completely agnostic about these "cross cutting concerns" (=cache, auth, or log) These are bound dynamically in runtime context.

@harikt
Copy link
Author

harikt commented Aug 6, 2014

@koriym How are you setting the locale of the language from the route?

@koriym
Copy link

koriym commented Aug 6, 2014

@harikt not have that functionality currently. But probably we treat the locale as a dependency. So the router detects the language, then make it "language-context" to change dependency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment