cormy / server-middleware-dispatcher
Cormy PSR-7 server middleware dispatcher
0.1.0
2016-11-23 10:13 UTC
Requires
- php: >=7
- cormy/server-middleware: ^0.1.0
- cormy/server-request-handler: ^0.1.0
- psr/http-message: ^1.0
Requires (Dev)
This package is not auto-updated.
Last update: 2024-12-21 21:36:43 UTC
README
🔩 Cormy PSR-7 server middleware dispatcher
Install
composer require cormy/server-middleware-dispatcher
Usage
use Cormy\Server\MiddlewareDispatcher; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; $middleware = function (ServerRequestInterface $request):\Generator { // delegate $request to the next request handler, i.e. the $finalHandler below $response = (yield $request); return $response->withHeader('X-PoweredBy', 'Unicorns'); }; $finalHandler = function (ServerRequestInterface $request):ResponseInterface { return new \Zend\Diactoros\Response(); }; // create a dispatcher $dispatcher = new MiddlewareDispatcher($middleware, $finalHandler); // dispatch a request $response = $dispatcher(new \Zend\Diactoros\ServerRequest());
API
Cormy\Server\MiddlewareDispatcher implements Cormy\Server\RequestHandlerInterface
MiddlewareDispatcher::__construct
/** * Create a Cormy PSR-7 server middleware dispatcher. * * @param callable|MiddlewareInterface $middleware * @param callable|RequestHandlerInterface $finalHandler */ public function __construct(callable $middleware, callable $finalHandler)
Inherited from Cormy\Server\RequestHandlerInterface::__invoke
/** * Process an incoming server request and return the response. * * @param ServerRequestInterface $request * * @return ResponseInterface */ public function __invoke(ServerRequestInterface $request):ResponseInterface;
Related
- Cormy\Server\Onion – Onion style PSR-7 middleware stack using generators
- Cormy\Server\Bamboo – Bamboo style PSR-7 middleware pipe using generators
- Cormy\Server\RequestHandlerInterface – Common interfaces for PSR-7 server request handlers
- Cormy\Server\MiddlewareInterface – Common interfaces for Cormy PSR-7 server middlewares
License
MIT © Michael Mayer