-
Notifications
You must be signed in to change notification settings - Fork 719
-
Notifications
You must be signed in to change notification settings - Fork 719
Controller After Handler #336
Comments
I'm going to create a pull request for this what do you think is the best solution: 1 - Replicate the "middleware handlers" behavior with a different name |
I have been thinking about moving to a more generic middleware stack à la connect/express. IMO the current architecture cannot hold the added complexity of specific after middlewares. If we want to support this, we need to simplify the architecture so that there is no difference between controllers and middleware handlers. |
My personal opinion is that the current naming of middleware handlers is not precisely correct. A middleware should be something which wraps the controller. This means a middleware needs to be able to alter not only the request (as it is now) but to alter also the response. To reduce complexity I would rename "middleware" to "before" and introduce an "after" filter which can be bound to the controller:
I think this approach would be much more consistent. |
see #362 |
Looks good to me, that was what I was thinking about. |
Commits ------- d53119e added a route after middleware 794b3c2 renamed middleware() to before() Discussion ---------- Implements route after middleware (closes silexphp#336) This PR renames the `middleware` method to `before` and adds a new `after` route middleware. These changes make Silex more consistent from a user point of view: * he can do something before the route callback on an application, a route collection, or just a route (by calling the `before` method on these objects); * he can do something after the route callback by calling the `after` method on an application, a route collection, or just a route. --------------------------------------------------------------------------- by fabpot at 2012-06-13T18:20:37Z I thought about using the `middleware` method for both before and after by passing the callback as an argument. But this has several drawback: * we loose the symmetry with the application before/after calls; * the developer must remember to manually call the callback (and symfony1 proves that many devs actually forgets about that); * this would act as a filter chain where the order of execution is not always clear when you have many filters.
I would like to have a way to define an handler similar to "middleware handlers" but that is executed after the controller action is called and before the "$app->after".
The reason why I don't want to use the "$app->after" is that I want to define this handler just for a Controller Provider not for the entire App.
The text was updated successfully, but these errors were encountered: