Skip to content
This repository has been archived by the owner on May 12, 2019. It is now read-only.

A simple session solution, based on the PSR7Session (client side session).

License

Notifications You must be signed in to change notification settings

chubbyphp-legacy/chubbyphp-session

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chubbyphp-session

Build Status Scrutinizer Code Quality Code Coverage Total Downloads Monthly Downloads Latest Stable Version Latest Unstable Version

Description

A simple session solution, based on the PSR7Session (client side session).

Requirements

  • php: ~7.0
  • psr7-sessions/storageless: ~3.0

Suggest

  • pimple/pimple: ~3.0

Installation

Through Composer as chubbyphp/chubbyphp-session.

composer require chubbyphp/chubbyphp-session "~1.1"

Usage

Session

<?php

use Chubbyphp\Session\FlashMessage;
use Chubbyphp\Session\Session;
use Psr\Http\Message\ServerRequestInterface as Request;

$session = new Session();

// check for existing key
$session->has($request, 'some.key');

// get value for existing key
$session->get($request, 'some.key', null);

// set value for key
$session->set($request, 'some.key', 'some.value');

// remove existing key
$session->remove($request, 'some.key');

// add flash message
$session->addFlash($request, new FlashMessage(FlashMessage::TYPE_SUCCESS, 'successfully saved'));

// get flash message
$flashMessage = $session->getFlash($request); // removes the flash from session

SessionMiddleware

<?php

$app = ...

// sample for slim
$app->add($container['session.middleware']);

SessionProvider (Pimple)

<?php

use Chubbyphp\Session\Session;
use Chubbyphp\Session\SessionProvider;
use Pimple\Container;

$container->register(new SessionProvider);

// replaceable configuration (set before first middleware use)
$container['session.expirationTime'] = 1200;
$container['session.privateRsaKey'] = '';
$container['session.publicRsaKey'] = '';

$container['session.setCookieHttpOnly'] = true;
$container['session.setCookiePath'] = '/';
$container['session.setCookieSecureOnly'] = true;

/** @var Session $session */
$session = $container['session'];

Copyright

Dominik Zogg 2016

About

A simple session solution, based on the PSR7Session (client side session).

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages