Skip to content

zobzn/psr7-stack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zobzn/psr7-stack

Build Status Software License

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);

About

PSR-7 HTTP Middleware Stack

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages