RouteDispatcher
Solo\Application\RouteDispatcher resolves and calls the handler stored on the request. It is the final handler of the pipeline that Application::handle() builds. See Route Handlers for usage.
php
final readonly class RouteDispatcher implements Psr\Http\Server\RequestHandlerInterfaceApplication registers it in the container.
__construct()
php
public function __construct(
ContainerInterface $container,
ResponseFactoryInterface $responseFactory
)$container resolves handlers given as IDs or [class, method] arrays. $responseFactory creates the response passed to the handler.
handle()
php
public function handle(ServerRequestInterface $request): ResponseInterface- Reads the
RequestAttribute::HANDLERattribute and throwsRouteNotFoundExceptionif it is missing. - Resolves the handler:
- a string is taken from the container, unless the container does not have it and PHP can call it, such as a function name or
'Class::staticMethod'; - a
[class-string, method]array calls the method on the instance from the container, unless the method is static; - anything else is used as it is.
- a string is taken from the container, unless the container does not have it and PHP can call it, such as a function name or
- Calls it with the request,
$responseFactory->createResponse()and theRequestAttribute::PARAMSattribute,[]if missing. - Returns the response.
Throws:
RouteNotFoundExceptionif the request has no handler;InvalidArgumentExceptionif the handler cannot be called, for example a method that does not exist;UnexpectedValueExceptionif the handler returns anything but aResponseInterface;- whatever the container or the handler throws.