damess/expressive-session-middleware

Simple session middleware for Zend Expressive

1.0.2 2016-06-28 12:35 UTC

This package is not auto-updated.

Last update: 2024-10-23 23:03:23 UTC


README

Software License Build Status Downloads

Simple session middleware for Zend Expressive

Install

Via Composer

$ composer require damess/expressive-session-middleware

Usage

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' => [
        'always' => [
            'middleware' => [
                DaMess\Http\SessionMiddleware::class,
            ],
            'priority' => 10000,
        ],
    ],
];

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(\DaMess\Http\SessionMiddleware::KEY);
}

Configuration

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,
    ],
];

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

License

The MIT License (MIT). Please see License File for more information.