# HttpSoft\Router middleware

The HttpSoft\Router package middleware classes that implements Psr\Http\Server\MiddlewareInterface.

All middleware contains only one public method Psr\Http\Server\MiddlewareInterface::process().

public function process(
    ServerRequestInterface $request, 
    RequestHandlerInterface $handler
): ResponseInterface;

# HttpSoft\Router\Middleware\RouteMatchMiddleware

Uses the route collector to match against the incoming request, and injects the request passed to the handler with the HttpSoft\Router\Route instance matched (using the HttpSoft\Router\Route class name as the attribute name).

If no route matches the request, the handler will be injected with the request without an instance of the HttpSoft\Router\Route.

public function __construct(
    HttpSoft\Router\RouteCollector $router,
    Psr\Http\Message\ResponseFactoryInterface $responseFactory,
    array $allowedMethods = ['HEAD'] // common allowed request methods for all routes.
);

If the request URI matches one of the routes, but the request method does not match that route's method, this middleware will emit a 405 response, along with an Allow header indicating the allowed route methods.

Source code on GitHub.

# HttpSoft\Router\Middleware\RouteDispatchMiddleware

Checks for a matched route (HttpSoft\Router\Route instance) in the request. If it is passed, the route handler is used, otherwise request processing is delegated to the passed handler.

public function __construct(HttpSoft\Runner\MiddlewareResolverInterface $resolver);

If a matching route was passed, an instance of the HttpSoft\Runner\MiddlewareResolverInterface from the HttpSoft\Runner package is used to resolve the route handler.

Source code on GitHub.