2017 © Pedro Peláez
 

library builder

Builder for stack middlewares based on HttpKernelInterface.

image

stack/builder

Builder for stack middlewares based on HttpKernelInterface.

  • Wednesday, December 20, 2017
  • by igorw
  • Repository
  • 14 Watchers
  • 253 Stars
  • 9,548,260 Installations
  • PHP
  • 59 Dependents
  • 4 Suggesters
  • 26 Forks
  • 2 Open issues
  • 7 Versions
  • 5 % Grown

The README.md

Stack/Builder

Builder for stack middlewares based on HttpKernelInterface., (*1)

Stack/Builder is a small library that helps you construct a nested HttpKernelInterface decorator tree. It models it as a stack of middlewares., (*2)

Example

If you want to decorate a silex app with session and cache middlewares, you'll have to do something like this:, (*3)

use Symfony\Component\HttpKernel\HttpCache\Store;

$app = new Silex\Application();

$app->get('/', function () {
    return 'Hello World!';
});

$app = new Stack\Session(
    new Symfony\Component\HttpKernel\HttpCache\HttpCache(
        $app,
        new Store(__DIR__.'/cache')
    )
);

This can get quite annoying indeed. Stack/Builder simplifies that:, (*4)

$stack = (new Stack\Builder())
    ->push('Stack\Session')
    ->push('Symfony\Component\HttpKernel\HttpCache\HttpCache', new Store(__DIR__.'/cache'));

$app = $stack->resolve($app);

As you can see, by arranging the layers as a stack, they become a lot easier to work with., (*5)

In the front controller, you need to serve the request:, (*6)

use Symfony\Component\HttpFoundation\Request;

$request = Request::createFromGlobals();
$response = $app->handle($request)->send();
$app->terminate($request, $response);

Stack/Builder also supports pushing a callable on to the stack, for situations where instantiating middlewares might be more complicated. The callable should accept a HttpKernelInterface as the first argument and should also return a HttpKernelInterface. The example above could be rewritten as:, (*7)

$stack = (new Stack\Builder())
    ->push('Stack\Session')
    ->push(function ($app) {
        $cache = new HttpCache($app, new Store(__DIR__.'/cache'));
        return $cache;
    })
;

Inspiration

The Versions

20/12 2017

dev-master

9999999-dev

Builder for stack middlewares based on HttpKernelInterface.

  Sources   Download

MIT

The Requires

 

The Development Requires

stack

18/11 2017

v1.0.5

1.0.5.0

Builder for stack middlewares based on HttpKernelInterface.

  Sources   Download

MIT

The Requires

 

The Development Requires

stack

02/06 2016

v1.0.4

1.0.4.0

Builder for stack middlewares based on HttpKernelInterface.

  Sources   Download

MIT

The Requires

 

The Development Requires

stack

23/11 2014

v1.0.3

1.0.3.0

Builder for stack middlewares based on HttpKernelInterface.

  Sources   Download

MIT

The Requires

 

The Development Requires

stack

28/01 2014

v1.0.2

1.0.2.0

Builder for stack middlewares based on HttpKernelInterface.

  Sources   Download

MIT

The Requires

 

The Development Requires

stack

25/10 2013

v1.0.1

1.0.1.0

Builder for stack middlewares based on HttpKernelInterface.

  Sources   Download

MIT

The Requires

 

The Development Requires

stack

02/08 2013

v1.0.0

1.0.0.0

Builder for stack middlewares based on HttpKernelInterface.

  Sources   Download

MIT

The Requires

 

The Development Requires

stack