Git Product home page Git Product logo

laravel-stack-middleware's Introduction

Stack Middleware for Laravel

Tests Packagist License Latest Stable Version Total Downloads Fruitcake

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

First, require this package in your composer file

composer require barryvdh/laravel-stack-middleware

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

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.

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.
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

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

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

Examples & Implementations

More information

For more information, read the StackPHP website.

License

MIT

laravel-stack-middleware's People

Contributors

barryvdh avatar hannesvdvreken avatar tortuetorche avatar okaufmann avatar omranic avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.