groton-school/session-cookie-middleware

Implementation of PSR-15 middleware to manage session cookies with CHIPS partition support

dev-main 2025-08-13 17:58 UTC

This package is auto-updated.

Last update: 2025-08-13 18:02:54 UTC


README

Implementation of PSR-15 middleware to manage session cookies with CHIPS partition support

Latest Version

Install

composer require groton-school/session-cookie-middleware

Use

In app/dependencies.php:

use DI;
use GrotonSchool\Session\Session;
use Odan\Session\SessionInterface;
use Odan\Session\SessionManagerInterface;

return function (ContainerBuilder $containerBuilder) {
    $containerBuilder->addDefinitions([

        // ...other dependencies...

        Session::class => function(ContainerInterface $container) {
            return new Session([
                'name' => 'session-cookie',
                'lifetime' => 86400,
                'path' => '/',
                'secure' => true,
                'httponly' => true,
                'partitioned' => false
            ]);
        },
        SessionInterface::class => DI\get(Session::class),
        SessionManagerInterface::class => DI\get(Session::class)
    ])
}

Either in app/routes.php:

use GrotonSchool\Session\SessionCookieMiddleware;

// ...

$app->get('/route/that/needs/session', SomeAction::class)
  ->add(SessionCookieMiddleware::class);

...or in app/middleware.php:

use GrotonSchool\Session\SessionCookieMiddleware;

// ...

$app->add(SessionCookieMiddleware::class);