2017 © Pedro Peláez
 

library laravel-stack-middleware

Stack Middleware for Laravel 5

image

barryvdh/laravel-stack-middleware

Stack Middleware for Laravel 5

  • Monday, February 19, 2018
  • by Barryvdh
  • Repository
  • 3 Watchers
  • 33 Stars
  • 78,732 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 13 Versions
  • 8 % Grown

The README.md

Stack Middleware for Laravel

Tests Packagist License Latest Stable Version Total Downloads Fruitcake, (*1)

Laravel 4 used HttpKernelInterface Middlewares for its Middleware, but Laravel 5 uses a new way. This package provides a way to wrap StackPHP Middleware so it can be used with Laravel 5, (*2)

First, require this package in your composer file, (*3)

composer require barryvdh/laravel-stack-middleware

After updating, add the ServiceProvider to the array of providers in config/app.php, (*4)

Barryvdh\StackMiddleware\ServiceProvider::class,

Usage

A Stack Middleware usually needs a Kernel. We can't use the real Kernel, so this package provides a one. You can use the bind method to wrap a Stack (HttpKernelInterface) middleware and register it in the App container. You can access the StackMiddleware class under the stack key in the Container, or with the Facade (Barryvdh\StackMiddleware\Facade). It can also be typehinted directly, eg. on the boot() method of a ServiceProvider., (*5)

The first argument is the new Middleware name. The second is either: - A closure, which gets the new Kernel as first parameter. - The name of the class to resolve with the App container. Parameters can be provided as an array as the third argument. The Kernel is prepended to that array, so it's always injected as first argument., (*6)

app('stack')->bind('AddRobotsHeaders', 'League\StackRobots\Robots', ['env' => 'production', 'envVar' => 'APP_ENV']);
use League\StackRobots\Robots;
use Barryvdh\StackMiddleware\StackMiddleware;

public function boot(StackMiddleware $stack) {
    $stack->bind('AddRobotsHeaders', function($kernel) {
        return new Robots($kernel, 'production', 'APP_ENV');
    });
}

Both examples have the same result, you can now add AddRobotsHeaders to the $middleware list in Kernel.php, (*7)

If you want to use the Facade, you can add that to your config/app.php. You can then use Stack::bind(...) instead., (*8)

    'Stack' => 'Barryvdh\StackMiddleware\Facade',

Examples & Implementations

  • StackRobots: Just require and use examples from above.
  • HttpCache: https://github.com/barryvdh/laravel-httpcache

More information

For more information, read the StackPHP website., (*9)

License

MIT, (*10)

The Versions

19/02 2018

dev-master

9999999-dev

Stack Middleware for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware stack stackphp

19/02 2018

v1.2.0

1.2.0.0

Stack Middleware for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware stack stackphp

14/06 2017

v1.1.1

1.1.1.0

Stack Middleware for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware stack stackphp

31/03 2017

v1.1.0

1.1.0.0

Stack Middleware for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware stack stackphp

26/01 2017

v1.0.1

1.0.1.0

Stack Middleware for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware stack stackphp

25/08 2016

v1.0.0

1.0.0.0

Stack Middleware for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware stack stackphp

25/08 2016

v0.2.4

0.2.4.0

Stack Middleware for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware stack stackphp

03/02 2016

v0.2.3

0.2.3.0

Stack Middleware for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware stack stackphp

22/12 2015

v0.2.2

0.2.2.0

Stack Middleware for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware stack stackphp

02/06 2015

v0.2.1

0.2.1.0

Stack Middleware for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware stack stackphp

18/02 2015

v0.2.0

0.2.0.0

Stack Middleware for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel middleware stack stackphp

17/02 2015

v0.1.1

0.1.1.0

Stack Middleware for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel middleware stack stackphp

17/02 2015

v0.1.0

0.1.0.0

Stack Middleware for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel middleware stack stackphp