ellipse/session-handler

Psr-15 middleware allowing to set a custom session handler

1.0.2 2018-02-23 14:00 UTC

This package is auto-updated.

Last update: 2024-11-26 00:49:20 UTC


README

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