# 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(
    Psr\Http\Message\ServerRequestInterface $request, 
    Psr\Http\Server\RequestHandlerInterface $handler
): Psr\Http\Message\ResponseInterface;

# HttpSoft\Router\Middleware\RouteMatchMiddleware

Using the route collector, it matches the incoming request with the added routes. If a match occurs, registers an instance of HttpSoft\Router\Route as a request attribute, using the HttpSoft\Router\Route class name as the attribute name, and passes the request to the next middleware. If no route matches the request, then the request will not be modified.

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 the existence of a matching route (instance of HttpSoft\Router\Route) as an attribute in the request. If it exists, the handler for this route is used, otherwise the request processing is delegated to the handler, which is passed as an argument to the process() method.

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.