2017 © Pedro Peláez
 

library bamboo

Bamboo style PSR-7 middleware pipe using generators

image

cormy/bamboo

Bamboo style PSR-7 middleware pipe using generators

  • Saturday, December 3, 2016
  • by schnittstabil
  • Repository
  • 1 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Cormy Bamboo Build Status Coverage Status Scrutinizer Code Quality

SensioLabsInsight, (*1)

:bamboo: Bamboo style PSR-7 middleware pipe using generators, (*2)

Install

composer require cormy/bamboo

Usage

use Cormy\Server\Bamboo;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

// create your bamboo stem nodes, aka middlewares
$nodes = [];

$nodes[] = function (ServerRequestInterface $request):\Generator {
    // delegate $request to the next request handler, i.e. the middleware right below
    $response = (yield $request);

    return $response->withHeader('X-PoweredBy', 'Unicorns');
};

$nodes[] = function (ServerRequestInterface $request):\Generator {
    // delegate $request to the next request handler, i.e. the $finalHandler below
    $response = (yield $request);

    return $response->withHeader('content-type', 'application/json; charset=utf-8');
};

// create the middleware pipe
$middlewarePipe = new Bamboo($nodes);

// create a handler for requests which reached the end of the pipe
$finalHandler = function (ServerRequestInterface $request):ResponseInterface {
    return new \Zend\Diactoros\Response();
};

// and dispatch a request
$response = $middlewarePipe->dispatch(new \Zend\Diactoros\ServerRequest(), $finalHandler);

API

Cormy\Server\Bamboo implements MiddlewareInterface

Bamboo::__construct

/**
 * Bamboo style PSR-7 middleware pipe.
 *
 * @param (callable|MiddlewareInterface)[] $nodes the middlewares, which requests pass through
 */
public function __construct(array $nodes)

Bamboo::dispatch

/**
 * Process an incoming server request and return the response.
 *
 * @param ServerRequestInterface           $request
 * @param callable|RequestHandlerInterface $finalHandler
 *
 * @return ResponseInterface
 */
public function dispatch(ServerRequestInterface $request, callable $finalHandler):ResponseInterface

Inherited from MiddlewareInterface::__invoke

/**
 * 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;

License

MIT © Michael Mayer, (*3)

The Versions

03/12 2016

dev-master

9999999-dev

Bamboo style PSR-7 middleware pipe using generators

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr psr-7 http request response pipe http-message bamboo cormy

23/11 2016

0.1.1

0.1.1.0

Bamboo style PSR-7 middleware pipe using generators

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr psr-7 http request response pipe http-message bamboo cormy

22/11 2016

0.1.0

0.1.0.0

Bamboo style PSR-7 middleware pipe using generators

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr psr-7 http request response pipe http-message bamboo cormy