First, it extracts the logic for producing a 405 response to new middleware, Zend\Expressive\Router\MethodNotAllowedMiddleware. This middleware checks for a route result that is due to method failure, and, in such a case, uses the composed response prototype. This change will allow users to substitute their own MethodNotAllowedMiddleware, allowing for templated solutions, or to omit it entirely, allowing fallback to the 404 handler.
Second, the RouteMiddleware was modified as follows:
it no longer requires a response prototype
it always injects the route result as a request attribute
it no longer produces a 405 response on its own
These changes mean the middleware does only what it says (routing).
Third, the Route class was modified to implement the PSR-15 MiddlewareInterface. When processed, it proxies to the composed middleware instance.
Fourth, the RouteResult was modified to implement the PSR-15 MiddlewareInterface. When processed, if it is a route failure, it delegates to the provided handler. If it is a successful route match, it proxies to the matched Route instance. The getMatchedMiddleware() method was removed, as it's essentially unnecessary; processing the route result accomplishes the same thing.
Fifth, the DispatchMiddleware was modified to process the RouteResult instance pulled from the request, instead of retrieving its composed middleware to process.
This patch accomplishes several things.
First, it extracts the logic for producing a 405 response to new middleware,
Zend\Expressive\Router\MethodNotAllowedMiddleware
. This middleware checks for a route result that is due to method failure, and, in such a case, uses the composed response prototype. This change will allow users to substitute their ownMethodNotAllowedMiddleware
, allowing for templated solutions, or to omit it entirely, allowing fallback to the 404 handler.Second, the
RouteMiddleware
was modified as follows:These changes mean the middleware does only what it says (routing).
Third, the
Route
class was modified to implement the PSR-15MiddlewareInterface
. When processed, it proxies to the composed middleware instance.Fourth, the
RouteResult
was modified to implement the PSR-15MiddlewareInterface
. When processed, if it is a route failure, it delegates to the provided handler. If it is a successful route match, it proxies to the matchedRoute
instance. ThegetMatchedMiddleware()
method was removed, as it's essentially unnecessary; processing the route result accomplishes the same thing.Fifth, the
DispatchMiddleware
was modified to process theRouteResult
instance pulled from the request, instead of retrieving its composed middleware to process.