I have read PSR-15 from PHP-FIG (HTTP Server Request Handler) and wondering when an action is called (Controller action or Closure).
When processing through all middlewares the action should be called after passing all middlewares. After the action all middlewares are passed again from the inside to the outside (as described in the User Guide from Slim Framework).
I browsed the Code from Laravel on GitHub, but can't figure out how they call the action and then traverse all of the middlewares again.
This answer tells me that Slim adds itself to the middleware stack. I guess it then executes the action somehow. However, Slim is using double pass.
How does a middleware stack and execution look with single pass (as described in PSR-15) and call an action between all of the middlewares?
Here is an example code as I could imagine that could work. Of course, there are a lot of things missing like setting routes, resolving dependencies, PSR interfaces and other things that come with frameworks.
This codes adds middleware and action to the request handler and the request handler can execute both when needed.