Simple session middleware for Zend Expressive
Via Composer
$ composer require damess/expressive-session-middleware
Add the following factories to your container config
return [
'dependencies' => [
'factories' => [
DaMess\Http\SessionMiddleware::class => DaMess\Factory\SessionMiddlewareFactory::class,
Aura\Session\Session::class => DaMess\Factory\AuraSessionFactory::class,
],
],
];
Set up the pre-routing middleware.
return [
'middleware_pipeline' => [
'pre_routing' => [
[
'middleware' => DaMess\Http\SessionMiddleware::class,
]
],
'post_routing' => [
],
],
];
Get the session object from the request
/**
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response)
{
/**
* @var \Aura\Session\Session $session
*/
$session = $request->getAttribute('session');
}
The session can be configured by adding the following data to your configuration i.e. session.global.php. See session.global.php.dist
return [
'session' => [
'name' => 'PHPSESSID',
'lifetime' => 7200,
'path' => null,
'domain' => null,
'secure' => false,
'httponly' => true,
],
];
Please see CHANGELOG for more information what has changed recently.
$ composer test
Please see CONTRIBUTING and CONDUCT for details.
The MIT License (MIT). Please see License File for more information.