zendframework / zend-stratigility

Middleware for PHP built on top of PSR-7 and PSR-15
BSD 3-Clause "New" or "Revised" License
235 stars 57 forks source link

LIFO instead of FIFO #173

Closed higoka closed 6 years ago

higoka commented 6 years ago

I was testing around with stratigility and in the docs it says the middleware execution order is FIFO. But in reality is LIFO.

I created a gist with the example im using: https://gist.github.com/higoka/78f875ad30a8c61127b61c8b4cffb0f7

The result i get is: 3 2 1 But with FIFO i would expect: 1 2 3

Ocramius commented 6 years ago

$handler->handle($req); is being called before your Stream#write() operation, so that's why the order is completely messed up.

Move the write() call to the first operation in each middleware.

higoka commented 6 years ago

Dont know exactly what you mean, can you show?

Ocramius commented 6 years ago

Ah, I see where the confusion is: the $response is indeed produced in the inner-most middleware, so it cannot be written upon before passing to the next layer.

I'm re-writing your example by modifying $request instead:

https://gist.github.com/Ocramius/2fe892d36c54811e0cb60ba9b5db5c29

higoka commented 6 years ago

Ah, now i see. Thanks for clarification.

Ocramius commented 6 years ago

@higoka :+1: