Unfortunately, neither is sufficient. I’m trying to determine whether it’s possible to specify some app middleware to run before the route is determined, and some after:
This is necessary because some middlewares parse, and potentially manipulate, the Request in ways which would affect routing, while other middlewares depend on the route to make choices.
The only workaround I can imagine is making an artificial “all routes” route group and adding the “post-routing-app-middleware” to that. I’m hoping there’s a happier solution.
In my case, I use it to add additional steps before and after these flows to show proper information, access, extra information, etc. to the user.
Example 1 (before): get a header’s authorization token (JWT) to know if the user has access to non-public URLs Example 2 (before): using the previous token I could validate if the user has access to a specific URL using an ACL (Access Control List) component Example 3 (after): You could minify HTML with a middleware getting the content type and removing comments, extra spaces, etc.
Thanks, but I don’t see how this is relevant: my question was about the order+timing of when Slim invokes middleware, and the extent to which that can be controlled; not about the basics of what middleware is in general.
The first middleware added is the latest being processed, but this depends on when are you returning the response object gotten by the “$next” callable.