Skip to content

PSR 15: RequestHandler Example

Terry L edited this page Jun 20, 2020 · 5 revisions
Clone this wiki locally

HTTP Server Request Handlers

Namespace

Shieldon\Psr15\RequestHandler

RequestHandler

__construct($fallbackHandler)

  • param RequestHandlerInterface fallbackHandler * The request handler.

Example:

$finalHandler = new FinalHandler();

$app = new RequestHandler($finalHandler);
$app->add(new ApiMiddleware());
$app->add(new StringMiddleware());

$response = $app->handle(ServerRequestFactory::fromGlobal());

add($middleware)

  • param MiddlewareInterface middleware * The middleware.
  • return void

Example:

$app->add(new ApiMiddleware());

handle(request)

  • param ServerRequestInterface request * The server request.
  • return ResponseInterface

Example:

$response = $app->handle(ServerRequestFactory::fromGlobal());