2017 © Pedro Peláez
 

library psr7-middleware-stack

Stack PSR-7 middlewares in a reusable way.

image

schnittstabil/psr7-middleware-stack

Stack PSR-7 middlewares in a reusable way.

  • Friday, April 8, 2016
  • by schnittstabil
  • Repository
  • 1 Watchers
  • 5 Stars
  • 34,560 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Psr7\MiddlewareStack Build Status Coverage Status Scrutinizer Code Quality Code Climate

SensioLabsInsight, (*1)

Stack PSR-7 middlewares in a reusable way :dango:, (*2)

Install

$ composer require schnittstabil/psr7-middleware-stack

Usage

add($someMiddleware4)
  ->add($someMiddleware3)
  ->add(
    function (RequestInterface $req, ResponseInterface $res, callable $next) {
      $res->getBody()->write('Greetings from the the 2nd middleware.');
      return $next($req, $res);
    }
  )
  ->add($someMiddleware1);
?>

Slim Example

Suppose we want to minify the response of some, but not all routes by Oscar Otero's psr7-middlewares in a reusable way., (*3)

Install dependencies:

$ composer require slim/slim
$ composer require oscarotero/psr7-middlewares
$ composer require mrclay/minify
$ composer require willdurand/negotiation

app.php

getContainer()['minifyMiddleware'] = function ($c) {
    return (new MiddlewareStack())
        ->add(Middleware::Minify())
        ->add(Middleware::FormatNegotiator());
};

$app->get('/', function (RequestInterface $request, ResponseInterface $response) {
    $body = '

Hello world!

'; return $response->write($body); })->add('minifyMiddleware'); $app->run(); ?>

License

MIT © Michael Mayer, (*4)

The Versions