thephpleague / route

Fast PSR-7 based routing and dispatch component including PSR-15 middleware, built on top of FastRoute.
http://route.thephpleague.com
MIT License
651 stars 126 forks source link

Why isn't the middleware stack executed for unmatched routes? #319

Open switchplane-tom opened 2 years ago

switchplane-tom commented 2 years ago

Correct me if I'm wrong, but the middleware stack is only executed when a route is matched. Is there a reason for this?

Given that the middleware stack runs before a matched route's callable, it would seem to make more sense that the stack is executed regardless of whether a route is matched. Perhaps I'm missing something.

My use case is a middleware that will always check for HTTP auth - regardless of whether a route is matched or not.

Thanks

philipobenito commented 2 years ago

Just catching up on issues, I'll remind myself on this next week and get back to you

bertramakers commented 2 years ago

I have another use case for this: Rewriting the path of requests before they are matched, to support deprecated / legacy paths without having to register the route twice.