ellipse/

session-handler

允许设置自定义会话处理程序的Psr-15中间件

1.0.2 2018-02-23 14:00 UTC

This package is auto-updated.

Last update: 2024-08-26 00:22:07 UTC


README

此软件包提供了一个 Psr-15 中间件,允许您为应用程序设置自定义会话处理程序。

需求 php >= 7.0

安装 composer require ellipse/session-handler

运行测试 ./vendor/bin/kahlan

使用设置会话处理程序中间件

例如,可以使用一个自定义会话处理程序,它使用Psr-6的实现,而不是内置的会话处理程序

<?php

namespace App;

use Cache\Adapter\Predis\PredisCachePool;
use Cache\SessionHandler\Psr6SessionHandler;

use Ellipse\Session\SetSessionHandlerMiddleware;

// Get an implementation of php SessionHandlerInterface. Here a session handler
// managing data with redis is used.
$client = new \Predis\Client(...);

$pool = PredisCachePool($client);

$config = ['ttl'=>3600, 'prefix'=>'foobar'];

$handler = new Psr6SessionHandler($pool, $config);

// This middleware will set $handler as the session handler. Obviously it should
// be processed before any call to session_start().
$middleware = new SetSessionHandlerMiddleware($handler);