cormy / server-middleware
Common interfaces for Cormy PSR-7 server middlewares
0.1.0
2016-11-20 20:39 UTC
Requires
- php: >=7
- psr/http-message: ^1.0
Requires (Dev)
This package is not auto-updated.
Last update: 2024-12-22 01:29:52 UTC
README
🔩 Common interfaces for Cormy PSR-7 server middlewares
Install
composer require cormy/server-middleware
Usage
use Generator; use Cormy\Server\MiddlewareInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; class Middleware implements MiddlewareInterface { /** * Process an incoming server request and return the response, optionally delegating * to the next request handler. * * @param ServerRequestInterface $request * * @return Generator yields PSR `ServerRequestInterface` instances and returns a PSR `ResponseInterface` instance */ public function __invoke(ServerRequestInterface $request):Generator { // delegate $request to the next request handler $response = yield $request; // mofify the response $response = $response->withHeader('X-PoweredBy', 'Unicorns'); return $response; } }
License
MIT © Michael Mayer