The Laravel Bridge use on Slim framework

v0.1.0 2019-06-18 09:22 UTC

README

Build Status codecov Latest Stable Version Total Downloads License

The bridge for Laravel in Slim framework

Installation

Using Composer to install package:

composer require laravel-bridge/slim

Replace class name Slim\App to bridge class LaravelBridge\Slim\App:

// Rename use class
use LaravelBridge\Slim\App;

// Or rename new instace class
$app = new \LaravelBridge\Slim\App();

Finally, it will work on most Slim project. Here has an example for more detail.

Using Laravel Service

LaravelBridge\Slim\App will use the Slim default service (e.g. Slim\Handlers\Error). If you want to use the Laravel Error handler, you can set the second argument, It will use all Laravel service defined in this bridge.

$app = new App([], true);

If you want to use some of Laravel service, use the ContainerBuilder.

$container = (new ContainerBuilder)
    ->useLaravelErrorHandler()
    ->useLaravelNotFoundHandler()
    ->build();

$app = new App($container);

foundHandler

The foundHandler in Slim is invoke when the route found.

This bridge implements a auto injection handler like Laravel, names RequestResponse. Use Laravel Service or call ContainerBuilder::useLaravelFoundHandler() can enable handler.

$container = (new ContainerBuilder)
    ->useLaravelFoundHandler()
    ->build();

$app = new App($container);

$app->get('/', function (IlluminateRequest $request, $args) {
    // Auto-inject Illuminate Request in clousre
});

settings

Slim use the Collection class, Laravel Bridge use the Fluent class.