amphp/aerys-session

v0.2.2 2017-07-18 07:35 UTC

README

License

amphp/aerys-session is a non-blocking session handler for use with amphp/aerys.

Requirements

  • PHP 7

Installation

composer require amphp/aerys-session

Registering the Session Middleware

$redis = new Amp\Redis\Client("tcp://localhost:6379");
$mutex = new Amp\Redis\Mutex("tcp://localhost:6379");

$router->use(
    Aerys\session(new Aerys\Session\Redis($redis, $mutex))
);

Using the Session

public function respondToRequest(Request $request, Response $response) {
    $session = new Aerys\Session($request);

    // you need to read the session before you can access the data from it
    yield $session->read();

    if (!$session->has("user")) {
        $response
            ->setStatus(401)
            ->end("Unauthorised");

        return;
    }

    $user = $session->get("user");

    // ...

    // you need to open the session for writing before you can write to it
    yield $session->open();

    $session->set("token", $token);

    // don't forget to save the session...
    yield $session->save();
}

Documentation

Security

If you discover any security related issues, please email bobwei9@hotmail.com or me@kelunik.com instead of using the issue tracker.

License

The MIT License (MIT). Please see LICENSE for more information.