2017 © Pedro Peláez
 

library session

Anax Session module.

image

anax/session

Anax Session module.

  • Wednesday, April 25, 2018
  • by mikael_roos
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3,512 Installations
  • PHP
  • 24 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 11 Versions
  • 12 % Grown

The README.md

Anax Session

Latest Stable Version Join the chat at https://gitter.im/canax/session, (*1)

Build Status CircleCI, (*2)

Build Status Scrutinizer Code Quality Code Coverage, (*3)

Maintainability Codacy Badge SensioLabsInsight, (*4)

Anax Session module, for wrapping the session and providing useful helpers related to the session., (*5)

The Session module is prepared wo be used for unit testing when run in CLI environment., (*6)

Table of content

Class, interface, trait

The following classes, interfaces and traits exists., (*7)

Class, interface, trait Description
Anax\Session\Session Wrapper class for sessions.
Anax\Session\SessionInterface Interface to implement for classes what want to wrap the session.
Anax\Session\SessionConfigurable Extending wrapper class with ability to read its configuration from a file.

Exceptions

There are no module specific exceptions., (*8)

Configuration file

This is a sample configuration file, it is usually stored in config/session.php., (*9)

<?php
/**
 * Config-file for sessions.
 */
return [
    // Session name
    //"name" => preg_replace("/[^a-z\d]/i", "", __DIR__),
    "name" => preg_replace("/[^a-z\d]/i", "", ANAX_APP_PATH),
];

DI service

The session is created as a framework service within $di. The following is a sample on how the session service is created., (*10)

<?php
/**
 * Configuration file for session service.
 */
return [
    // Services to add to the container.
    "services" => [
        "session" => [
            "shared" => true,
            "callback" => function () {
                $obj = new \Anax\Session\SessionConfigurable();
                $obj->configure("session.php");
                return $obj;
            }
        ],
    ],
];
  1. The object is created.
  2. The configuration file is read and applied.

The service is lazy loaded and not created until it is used., (*11)

Access as framework service

You can access the module as a framework service., (*12)

# $app style
$app->session->start();

# $di style, two alternatives
$di->get("session")->start();

$session = $di->get("session");
$session->start();

Start the session

You can start the session anywhere. A good place to do this is in the frontkontroller index.php, after you have created $di (and $app). The session will then be available for all page requests., (*13)

You start the session by accessing it., (*14)

# $app style
$app->session->start();

The session will not start when running in CLI (for example PHPUnit), but it will still be active and usable., (*15)

Work with session variables

There are helpers to use when reading and setting values in the session., (*16)

# Check if a key is set in the session
$app->session->has($key);

# Get a value from the session, null if it is not set.
$app->session->get($key);

# Get a value from the session or get the default value.
$app->session->get($key, $default);

# Set a value in the session, associated with a key.
$app->session->set($key, $value);

# Delete a key from the session.
$app->session->delete($key);

Session flash messages

There is feature useful for flash messages. A value is retrieved from the session and is then deleted., (*17)

# Get the value from the session and then delete its key, default is null.
$app->session->getOnce($key);

# Specify your own default value when key does not exists.
$app->session->getOnce($key, $default);

Debug the session

You can var_dump the session object and it will print out the content of $_SESSION., (*18)

# Debug the session and review its content through var_dump.
var_dump($app->session);

Destroy the session

You can destroy the session which might be useful during development., (*19)

# Destroy the session.
$app->session->destroy();

License

This software carries a MIT license. See LICENSE.txt for details., (*20)

 .  
..:  Copyright (c) 2013 - 2018 Mikael Roos, mos@dbwebb.se

The Versions

25/04 2018

dev-master

9999999-dev https://dbwebb.se/anax

Anax Session module.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

micro framework boilerplate mvc education

25/04 2018

v1.0.10

1.0.10.0 https://dbwebb.se/anax

Anax Session module.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

micro framework boilerplate mvc education

23/04 2018

v1.0.9

1.0.9.0 https://dbwebb.se/anax

Anax Session module.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

micro framework boilerplate mvc education

16/04 2018

v1.0.8

1.0.8.0 https://dbwebb.se/anax

Anax Session module.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

micro framework boilerplate mvc education

15/10 2017

v1.0.6

1.0.6.0 https://dbwebb.se/anax

Anax Session module.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

micro framework boilerplate mvc education

05/10 2017

v1.0.5

1.0.5.0 https://dbwebb.se/anax

Anax Session module.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

micro framework boilerplate mvc education

02/10 2017

v1.0.4

1.0.4.0 https://dbwebb.se/anax

Anax Session module.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

micro framework boilerplate mvc education

17/08 2017

v1.0.3

1.0.3.0 https://dbwebb.se/anax

Anax Session module.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

micro framework boilerplate mvc education

17/08 2017

v1.0.2

1.0.2.0 https://dbwebb.se/anax

Anax Session module.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

micro framework boilerplate mvc education

26/06 2017

v1.0.1

1.0.1.0 https://dbwebb.se/anax

Anax Session module.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

micro framework boilerplate mvc education

04/05 2017

v1.0.0

1.0.0.0 https://dbwebb.se/anax

Anax Session module.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

micro framework boilerplate mvc education