zobzn / psr7-stack
PSR-7 HTTP Middleware Stack
0.1.1
2016-07-24 14:57 UTC
Requires
- php: >=5.4
- psr/http-message: ^1.0
Requires (Dev)
- fabpot/php-cs-fixer: ^1.11
- phpunit/phpunit: ^4.8
- zendframework/zend-diactoros: ^1.3
This package is not auto-updated.
Last update: 2025-01-02 01:22:10 UTC
README
PSR-7 HTTP Middleware Stack
Installation
composer require zobzn/psr7-stack
Basic Usage
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; require_once __DIR__ . '/vendor/autoload.php'; $stack = new \Zobzn\Stack(); $stack->push(function (ServerRequestInterface $request, ResponseInterface $response, callable $next = null) { // do something with request and/or response return $next ? $next($request, $response) : $response; }); $stack->push(function (ServerRequestInterface $request, ResponseInterface $response, callable $next = null) { // do something else with request and/or response return $next ? $next($request, $response) : $response; }); $request = new SomeServerRequestImplementation(); $response = new SomeResponseImplementation(); // execute middlewares on given request and response, and get final response $response = $stack->__invoke($request, $response);