Request handler callable
This package provides a Psr-15 request handler proxying a callable., (*1)
Require php >= 7.0, (*2)
Installation composer require ellipse/handlers-callable
, (*3)
Run tests ./vendor/bin/kahlan
, (*4)
Using callables as request handlers
The class Ellipse\Handlers\CallableRequestHandler
can be wrapped around a callable in order to use it as a request handler., (*5)
As any request handler ->handle()
method, the callable takes an implementation of Psr\Http\Message\ServerRequestInterface
as parameter and should return an implementation of Psr\Http\Message\ResponseInterface
., (*6)
<?php
namespace App;
use Psr\Http\Message\ServerRequestInterface;
use Ellipse\Handlers\CallableRequestHandler;
// This request handler is wrapped around the given callable.
$handler = new CallableRequestHandler(function (ServerRequestInterface $request) {
// ...
return $response;
});
// The handler ->handle() method proxy the callable.
$response = $handler->handle($request);