Skip to content
docsv0.9.1

RequestHandler

The web entry point over a booted {@see Kernel}: matches the request against the kernel's `milpa/http` route table, composes the matched route's per-route PSR-15 `middleware[]` in front of the resolved controller, and dispatches — or answers 404/405 — never a legacy `Milpa\Web` request/response pair, only `psr/http-message` types, per this front's mandate to route+dispatch entirely on `milpa/http`. Resolving those middlewares from the DI container is the concrete `MiddlewareResolverInterface` the host kernel always owed `milpa/http` (see {@see ContainerMiddlewareResolver}). Building the 404/405 responses needs a concrete PSR-7 message implementation, so this class takes a PSR-17 {@see ResponseFactoryInterface} instead of hardcoding one (nyholm, guzzle, …) — the host wires whichever implementation it already depends on.

RequestHandler::__construct()

public function __construct(Milpa\Runtime\Kernel $kernel, Psr\Http\Message\ResponseFactoryInterface $responseFactory):

Parameters

Parameters of __construct()
NameTypeDescription
$kernelMilpa\Runtime\Kernel
$responseFactoryPsr\Http\Message\ResponseFactoryInterface

RequestHandler::handle()

public function handle(Psr\Http\Message\ServerRequestInterface $request): Psr\Http\Message\ResponseInterface

Matches `$request` against the kernel's route table and returns the controller's response, or a 404/405 built from the injected response factory.

Parameters

Parameters of handle()
NameTypeDescription
$requestPsr\Http\Message\ServerRequestInterface