ellipsephp / session-handler

Psr-15 middleware allowing to set a custom session handler

Home Page:https://github.com/ellipsephp/session-handler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Session handler

This package provides a Psr-15 middleware allowing to set a custom session handler to your application.

Require php >= 7.0

Installation composer require ellipse/session-handler

Run tests ./vendor/bin/kahlan

Using the set session handler middleware

For example, a custom session handler using an implementation of Psr-6 can be used instead of the built in session handler:

<?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);

About

Psr-15 middleware allowing to set a custom session handler

https://github.com/ellipsephp/session-handler

License:MIT License


Languages

Language:PHP 100.0%