-
Notifications
You must be signed in to change notification settings - Fork 195
Rename post_routing pipeline config param? #266
Comments
There's a number of confusions that I'm observing. First "pipeline". Many are pointing out that a pipe is typically unidirectional. However, with middleware, we actually have two directions, as the middleware that first returns a response causes execution to return back out the path it traveled. This means that so-called "pre_routing" middleware might operate on the response returned by routed middleware, making it more like a "post" operation! As an example, consider the following middleware that adds a header to the returned response before returning it itself: function ($request, $response, $next)
{
$response = $next($request, $response);
return $response->withHeader('X-Clacks-Overhead', 'GNU Terry Pratchett');
} The above would be registered as pre_routing middleware if you want it to execute for any response returned! The next issue is then, of course, with the naming of The term "routing" was chosen for these configuration variables for affinity with the already established "routing middleware". Since we don't make any reference to "dispatching" in the code (other than So, the questions I have are:
|
@weierophinney Thanks for the explanations. The first term that came to my mind was "queue". If people queue in a bank they normally get "processed" consecutively. But people can swap their positions in the queue and some times some one is in such a hurry that he pushes to the front. For the "pre" and "post" terms I have no better suggestion. But I think it doesn't matter how these terms are called. A proper documentation will be essential, I think |
@RalfEggert The problem with queue as a term here is that typically once a queue item is processed, it's removed; with Stratigility, and thus Expressive, the response is returned back through every item; processing is not handed off to the I'm not sure if there's a good, more specific term, unfortunately, which makes me think that both terms (pipeline, pre/post-routing) simply need more explaining in the manual. Making a todo item for myself. |
👍 |
Why not use I also feel like the implementation seems kinda weird to me now that I know it moves back through the stack. What's the benefit to this over a simple pipeline? |
@nesl247 With regards to this:
I suggest you do some reading on middleware, and how it's used across the various languages. The approach used in Stratigility and Expressive mimics that in Sencha Connect, and is a pattern used in Rack (Ruby), WSGI (Python), and most major middleware implementations in other languages. The main difference between Connect and Rack is that the "next" middleware (or, rather, the function for calling it) is passed on invocation, rather than as a property to the middleware. Regardless, the execution path is the same: each layer calls the next, and the response travels back out through the layers it traversed. The benefit is that you can layer your applications, and implement functionality such as caching without requiring multiple "hooks" or an event system. |
Thanks for the explanation. Was talking to a few people and we were curious about it. Guess there's no better name, so I'm looking forward to the improved documentation in the future. |
I would suggest renaming "pre_routing" and "post_routing" to "outer_routing" and "inner_routing" respectively as registering them in a pipeline defines a position and not a time of execution. It also fits well visually to the metaphor of an onion. Also if to follow that logic wouldn't the term "onion" be better suited than "pipeline" to the concept we operate on? The only problem with "onion" is that it is not well established computer science terminology ;). |
If we separate routing from dispatching (#259) then I'd suggest these keys:
Yeah, |
@RalfEggert and @danizord — please see #270 for an approach to this. In discussion with @ezimuel, we decided that we could have I'm still working on solutions for how to handle config merging (to ensure order is preserved), but feel it's a solvable problem. Please review! |
That PR will solve my problems within this issue. So it could be closed. I will comment in #270 |
Fixed with #270. |
When I started working with
Zend\Expressive
I stumbled upon thepost_routing
parameter in the middleware pipeline configuration. Coming fromZend\Mvc
I thought that these middleware will be executed directly after the routing. But through investigating it I noticed that these middleware are executed after the middleware for the current route. From that point of view the name sounds correct, but is leading to misunderstandings like here: #259My suggestion would be to rename
post_routing
topost_dispatching
to reduce future misinterpretations from new users.The text was updated successfully, but these errors were encountered: