Skip to content

samsonasik/expressive-session-middleware

 
 

Repository files navigation

expressive-session-middleware

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' => [
        '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');
}

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.

About

Session middleware for Zend Expressive using Aura Session

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%