Unofficial port of laravel's illuminate/session.
PHP
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
test
.gitignore
.travis.yml
LICENSE
README.md
composer.json
phpunit.xml

README.md

Laraport Session Build Status

This php library is an unofficial port of laravel (L4) sessions. See illuminate/session for more details. The reason for this port is to consume it outside of laravel in a standalone project or another framework, where you find it tediuos to import the whole laravel framework.

This port currently supports the following drivers:

Requires PHP 5.4 or greater.

I have tried my best to load the minimum required libraries and have avoided laravel's container to ensure maximum portability.

Table of contents

Install

This package can be installed by requiring it via composer.

$ composer require laraport/session

Usage

If you have consumed sessions in laravel (which i am sure you have), its now a cinch to consume it in a standalone project as well.

Array driver

The laravel configuration is loaded by default which is set to use the array driver.

<?php

require_once __DIR__ . '/vendor/autoload.php';

$Session = new Laraport\Session();
$Session->start();
// ...
$Session->put('laraport', 'session');
// ... You know the rest, right?

File driver

To consume the file session driver, you may override the necessary configuration.

<?php

require_once __DIR__ . '/vendor/autoload.php';

$Session = new Laraport\Session([
    'driver' => 'file',
    'files' => __DIR__ . '/path/to/session'
]);
$Session->start();
// ...

Database driver

For the database session driver, you will need to pass the database connection array and set the table.

Any connection that illuminate/database understands, is supported.

The table is set to sessions by default.

<?php

require_once __DIR__ . '/vendor/autoload.php';

$Session = new Laraport\Session([
    'driver' => 'database',
    'table' => 'sessions',
    'connection' => [
        'driver'   => 'sqlite',
        'database' => $database,
        'prefix'   => ''
    ]
]);
$Session->start();
// ...

Custom driver

A custom implementation of php's SessionHandlerInterface is also supported. Simply set the instance of the implementation as the driver .

<?php

require_once __DIR__ . '/vendor/autoload.php';

$Session = new Laraport\Session([
    'driver' => new MyCustomSessionHandler(/*...*/)
]);
$Session->start();
// ...

Test

First make sure you are in the project source directory.

Do a composer install.

$ composer install

Run the tests.

$ vendor/bin/phpunit

or

$ composer test

Similar projects

The above packages were the source of inspiration for this port.

License

Released under the MIT License.