2017 © Pedro Peláez
 

library dispatch

An HTTP Interop compatible middleware dispatcher

image

equip/dispatch

An HTTP Interop compatible middleware dispatcher

  • PHP
  • 10 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 11 Versions
  • 60 % Grown

The README.md

Equip Dispatch

Latest Stable Version License Build Status Code Coverage Scrutinizer Code Quality, (*1)

An HTTP Interop compatible middleware dispatcher in Equip. Attempts to be PSR-1, PSR-2, PSR-4, PSR-7, and PSR-15 compliant., (*2)

Heavily influenced by the design of Tari by ircmaxwell., (*3)

For more information, see the documentation., (*4)

Install

composer require equip/dispatch

Usage

The MiddlewareCollection is a container for middleware that acts as the entry point. It takes two arguments:, (*5)

  • An array of $middleware which must be instances of server middleware.
  • A callable $default that acts as the terminator for the collection and returns an empty response.

Once the collection is prepared it can dispatched with a server request and will return the response for output., (*6)

Example

use Equip\Dispatch\MiddlewareCollection;

// Any implementation of PSR-15 MiddlewareInterface
$middleware = [
    new FooMiddleware(),
    // ...
];

// Default handler for end of collection
$default = function (ServerRequestInterface $request) {
    // Any implementation of PSR-7 ResponseInterface
    return new Response();
};

$collection = new MiddlewareCollection($middleware);

// Any implementation of PSR-7 ServerRequestInterface
$request = ServerRequest::fromGlobals();
$response = $collection->dispatch($request, $default);

Nested Collections

The MiddlewareCollection also implements the MiddlewareInterface to allow collections to be nested:, (*7)

use Equip\Dispatch\MiddlewareCollection;

// Any implementation of PSR-15 MiddlewareInterface
$middleware = [
    new FooMiddleware(),

    // A nested collection
    new MiddlewareCollection(...),

    // More middleware
    new BarMiddleware(),
    // ...
];

$collection = new MiddlewareCollection($middleware);

// HTTP factories can also be used
$default = [$responseFactory, 'createResponse'];
$request = $serverRequestFactory->createRequest($_SERVER);

$response = $collection->dispatch($request, $default);

The Versions

26/01 2018

dev-master

9999999-dev

An HTTP Interop compatible middleware dispatcher

  Sources   Download

MIT

The Requires

 

The Development Requires

26/01 2018

2.0.0

2.0.0.0

An HTTP Interop compatible middleware dispatcher

  Sources   Download

MIT

The Requires

 

The Development Requires

29/11 2017

1.0.0

1.0.0.0

An HTTP Interop compatible middleware dispatcher

  Sources   Download

MIT

The Requires

 

The Development Requires

07/10 2017

0.5.0

0.5.0.0

An HTTP Interop compatible middleware dispatcher

  Sources   Download

MIT

The Requires

 

The Development Requires

13/04 2017

0.4.0

0.4.0.0

An HTTP Interop compatible middleware dispatcher

  Sources   Download

MIT

The Requires

 

The Development Requires

14/03 2017

0.3.1

0.3.1.0

An HTTP Interop compatible middleware dispatcher

  Sources   Download

MIT

The Requires

 

The Development Requires

17/01 2017

0.3.0

0.3.0.0

An HTTP Interop compatible middleware dispatcher

  Sources   Download

MIT

The Requires

 

The Development Requires

23/11 2016

0.2.0

0.2.0.0

An HTTP Interop compatible middleware dispatcher

  Sources   Download

MIT

The Requires

 

The Development Requires

14/11 2016

0.1.2

0.1.2.0

An HTTP Interop compatible middleware dispatcher

  Sources   Download

MIT

The Requires

 

The Development Requires

14/11 2016

0.1.1

0.1.1.0

An HTTP Interop compatible middleware dispatcher

  Sources   Download

MIT

The Requires

 

The Development Requires

14/11 2016

0.1.0

0.1.0.0

An HTTP Interop compatible middleware dispatcher

  Sources   Download

MIT

The Requires

 

The Development Requires