2017 © Pedro Peláez
 

library session

Psr-15 middleware allowing to use session with Psr-7 request and response

image

ellipse/session

Psr-15 middleware allowing to use session with Psr-7 request and response

  • Friday, April 27, 2018
  • by pmall
  • Repository
  • 1 Watchers
  • 1 Stars
  • 131 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 2 % Grown

The README.md

Session middleware

This package provides a Psr-15 middleware managing session. It works out of the box using the session configuration values, yet it is suited to the Psr-7 request/response abstraction., (*1)

Require php >= 7.0, (*2)

Installation composer require ellipse/session, (*3)

Run tests ./vendor/bin/kahlan, (*4)

Using the session middleware

<?php

use Ellipse\Dispatcher;
use Ellipse\Session\SessionMiddleware;

// By default SessionMiddleware uses php session configuration values.
$middleware = new SessionMiddleware

    // Will call php session_set_save_handler($handler) before starting the session.
    ->withSaveHandler($handler)

    // Will call php session_name('session_name') before starting the session.
    ->withName('session_name')

    // Will call php session_save_path('/session/save/path') before starting the session.
    ->withSavePath('/session/save/path')

    // Will call php session_cache_limiter('public') before starting the session.
    ->withCacheLimiter('public')

    // Will call php session_cache_expire(60) before starting the session.
    ->withCacheExpire(60)

    // Will call php session_set_cookie_params(3600, '/path', 'domain', true, true) before starting the session.
    ->withCookieParams([
        'lifetime' => 3600,
        'path' => '/path',
        'domain' => 'domain',
        'secure' => true,
        'httponly' => true,
    ]);

// Build a dispatcher using the session middleware.
$dispatcher = new Dispatcher([

    $middleware,

    // Next middleware have access to the request Ellipse\Session::class attribute.
    new class implements MiddlewareInterface
    {
        public function process(ServerRequestInterface $request, RequestHandlerInterface $handler)
        {
            // Session data is attached to the Ellipse\Session::class request attribute.
            $session = $request->getAttribute(Ellipse\Session::class);

            // Return the session id (session_id())
            $session->id();

            // Regenerate the session id (session_regenerate_id(bool $delete_old_session = false))
            $session->regenerate_id();

            // Set a session value.
            $session->set('key', 'value');

            // Set a session value only for the next session.
            $session->flash('key', 'value');

            // Return whether a session value is set.
            $session->has('key');

            // Return an array of all the session data.
            $session->all();

            // Return the value associated to the given key.
            $session->get('key');

            // Return a default value when the given key is not set.
            $session->get('notset', 'default');

            // Unset a session value.
            $session->unset('key');

            // Unset all session value.
            $session->delete();
        }
    }
]);

The Versions

27/04 2018

dev-master

9999999-dev https://github.com/ellipsephp/session

Psr-15 middleware allowing to use session with Psr-7 request and response

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar pmall

middleware psr-7 encryption session psr-6 psr-15

27/04 2018

0.3.0

0.3.0.0 https://github.com/ellipsephp/session

Psr-15 middleware allowing to use session with Psr-7 request and response

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar pmall

middleware psr-7 session psr-15

27/04 2018

0.2.0

0.2.0.0 https://github.com/ellipsephp/session

Psr-15 middleware allowing to use session with Psr-7 request and response

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar pmall

middleware psr-7 session psr-15

26/04 2018

0.1.0

0.1.0.0 https://github.com/ellipsephp/session

Psr-15 middleware allowing to use session with Psr-7 request and response

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar pmall

middleware psr-7 session psr-15