Lumen middleware pipeline execution order in grouped routes
0 reputation · 29 Jul 2023, 12:36 UTC
Lumen utilizes a FastRoute implementation and a middleware pipeline to filter incoming HTTP requests. When organizing an API, routes are often grouped to share common attributes, such as prefixes or specific middleware layers.
There is a need to determine the exact execution sequence when a request matches a route that is subject to both global middleware (defined in bootstrap/app.php) and route-specific middleware assigned via a group. It is unclear if the framework allows for a configurable priority between these two layers or if the global stack always precedes the group stack regardless of the registration order.
Technical Constraints
- Environment: Lumen (latest stable version)
- Requirement: Precise control over request filtering sequence for authentication and logging
Does the Lumen middleware pipeline execute global middleware before group-specific middleware in all scenarios? Is there a mechanism to inject a group-level middleware before the global stack?