ackee/laravel-session

该包已被放弃,不再维护。没有建议的替代包。

Laravel Session for Slim 3的桥梁

1.0.1 2015-07-08 11:34 UTC

This package is not auto-updated.

Last update: 2021-04-30 23:49:51 UTC


README

此中间件允许您使用Laravel 5.x Session库与Slim 3。它的好处是可以使用相同的API使用不同的Session存储。

安装

通过Composer

composer require ackee/laravel-session

如何使用

require __DIR__ . '/../vendor/autoload.php';

use Slim\Http\Request;
use Slim\Http\Response;

$app = new Slim\App();

$container = $app->getContainer();

// This is needed for file based session driver
$container['files'] = function () {
    return new Illuminate\Filesystem\Filesystem();
};

$container['config'] = new Illuminate\Config\Repository();

// These are the configs or you could load them from an external file 
// cf https://github.com/mattstauffer/Torch/blob/master/components/session/index.php

$container['config']['session.lifetime'] = 120; // Minutes idleable
$container['config']['session.expire_on_close'] = false;
$container['config']['session.lottery'] = array(2, 100); // lottery--how often do they sweep storage location to clear old ones?
$container['config']['session.cookie'] = 'laravel_session';
$container['config']['session.path'] = '/';
$container['config']['session.domain'] = null;
$container['config']['session.driver'] = 'file';
$container['config']['session.files'] = __DIR__ . '/sessions';

$container->register(new Ackee\LaravelSession\PimpleSessionServiceProvider);
$app->add(new Ackee\LaravelSession\Middleware($container->get('session')));

$app->get('/', function ($request, $response, $args) {
    $this->session->set('test', 'This is my session data');
    return $response->write('Session set.');
});

$app->get('/test', function ($request, $response, $args) {
    $test = $this->session->get('test');
    return $response->write($test);
});

$app->run();

许可

MIT许可(MIT)。请参阅许可文件以获取更多信息。