Skip to content
This repository has been archived by the owner on Jul 4, 2018. It is now read-only.
This repository has been archived by the owner on Jul 4, 2018. It is now read-only.

Controller After Handler #336

Closed
lightglitch opened this issue May 30, 2012 · 5 comments
Closed

Controller After Handler #336

lightglitch opened this issue May 30, 2012 · 5 comments

Comments

@lightglitch
Copy link

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.

@lightglitch
Copy link
Author

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
2 - Add a new parameter to the "middleware handlers" where you define if ti's executed before or after

@igorw
Copy link
Contributor

igorw commented May 30, 2012

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.

@webholics
Copy link

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:

$app->get('...', function() { ... })
->before(function(Request $request) { ... })
->after(function(Response $response) { ... });

I think this approach would be much more consistent.

@fabpot
Copy link
Member

fabpot commented Jun 13, 2012

see #362

@lightglitch
Copy link
Author

Looks good to me, that was what I was thinking about.

lyrixx pushed a commit to lyrixx/Silex that referenced this issue Jun 14, 2012
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.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

4 participants