2017 © Pedro PelĂĄez
 

library session-manager

Simple session management library written in PHP 7

image

codeinc/session-manager

Simple session management library written in PHP 7

  • Wednesday, March 14, 2018
  • by joanfabregat
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 38 Versions
  • 0 % Grown

The README.md

Session manager

This library is a simple session management service written in PHP 7. The library is compatible with PSR-15 and PSR-7. It provides a PSR-15 middleware to attach the session manager to the PSR-7 request object as an attribute., (*1)

Saving and writting the session goes through a session handler implementing HandlerInterface., (*2)

Usage

<?php
use CodeInc\SessionManager\SessionManager;

// the session manager need a session handler to start
$sessionManager = new SessionManager(
    new MySessionHandler() //  any handler implementing HandlerInterface
);
$sessionManager->setName("AGreatSession");
$sessionManager->setExpire(30); // minutes
$sessionManager->setValidateClientIp(true);
$session = $sessionManager->start($psr7ServerRequest); // the PSR-7 server request

// SessionManager implement ArrayAccess 
$session["test"] = "Hello wold!";
echo $session["test"];

// SessionManager is also iterable
foreach ($session as $var => $value) {
    echo "$var = $value\n";
}

Middleware

A PSR-15 middleware SessionMiddleware is provided to attach to session manager to the request object and to send out the session cookie by attaching them to the PSR-7 response. The cookie is only attached to text/html responses., (*3)

<?php
use CodeInc\SessionManager\SessionManager;
use CodeInc\SessionManager\SessionMiddleware;

// the middleware needs the session manager
$sessionManager = new SessionManager(new MySessionHandler());

// instantiating the middleware and processing the PSR-7 request, producing a PSR-7 response
// the middleware will take car of starting the session and will attache the session
// data to the PSR-7 request attributes.
$middleware = new SessionMiddleware($sessionManager);
$psr7Response = $middleware->process(
    $psr7ServerRequest, 
    $somePsr15RequestHandler
);

Withing a controller or another middleware you and access the session data from the PSR-7 request attributes using:, (*4)

<?php
use CodeInc\SessionManager\SessionMiddleware;

$session = SessionMiddleware::getSession($psr7ServerRequest);
$session["user_name"] = "John Smith";
echo $session["user_name"];

Installation

This library is available through Packagist and can be installed using Composer:, (*5)

composer require codeinc/session-manager

License

This library is published under the MIT license (see the LICENSE file)., (*6)

The Versions

14/03 2018
13/03 2018

2.0.3

2.0.3.0 https://github.com/CodeIncHQ/lib-session

Simple session management library written in PHP 7

  Sources   Download

MIT

The Requires

 

The Development Requires

13/03 2018

2.0.2

2.0.2.0 https://github.com/CodeIncHQ/lib-session

Simple session management library written in PHP 7

  Sources   Download

MIT

The Requires

 

The Development Requires

13/03 2018

2.0.1

2.0.1.0 https://github.com/CodeIncHQ/lib-session

Simple session management library written in PHP 7

  Sources   Download

MIT

The Requires

 

The Development Requires

13/03 2018

2.0

2.0.0.0 https://github.com/CodeIncHQ/lib-session

Simple session management library written in PHP 7

  Sources   Download

MIT

The Requires

 

The Development Requires

13/03 2018

1.4.1

1.4.1.0 https://github.com/CodeIncHQ/lib-session

Simple session management library written in PHP 7

  Sources   Download

MIT

The Requires

 

The Development Requires

13/03 2018

1.4.0

1.4.0.0 https://github.com/CodeIncHQ/lib-session

Simple session management library written in PHP 7

  Sources   Download

MIT

The Requires

 

The Development Requires

12/03 2018

1.3.4

1.3.4.0 https://github.com/CodeIncHQ/lib-session

Simple session management library written in PHP 7

  Sources   Download

MIT

The Requires

 

The Development Requires

08/03 2018

1.3.3

1.3.3.0 https://github.com/CodeIncHQ/lib-session

Simple session management library written in PHP 7

  Sources   Download

MIT

The Requires

 

The Development Requires

08/03 2018

1.3.2

1.3.2.0 https://github.com/CodeIncHQ/lib-session

Simple session management library written in PHP 7

  Sources   Download

MIT

The Requires

 

The Development Requires

08/03 2018

1.3.1

1.3.1.0 https://github.com/CodeIncHQ/lib-session

Simple session management library written in PHP 7

  Sources   Download

MIT

The Requires

 

The Development Requires