Session class.
Protected constructor since this is a static class.
NULL
protected function __construct()
{
// Nothing here
}
Starts a session using the chosen type of storage.
| Type | Description |
|---|---|
| string | (optional) Session configuration name |
NULL
public static function start($name = null)
{
$config = Config::get('session');
$name = ($name === null) ? $config['default'] : $name;
if(isset($config['configurations'][$name]) === false)
{
throw new RuntimeException(vsprintf("%s(): '%s' has not been defined in the session configuration.", array(__METHOD__, $name)));
}
$type = $config['configurations'][$name]['type'];
if(strtolower($type) !== 'native')
{
$class = '\mako\session\\' . $type;
$handler = new $class($config['configurations'][$name]);
session_set_save_handler
(
array($handler, 'open'),
array($handler, 'close'),
array($handler, 'read'),
array($handler, 'write'),
array($handler, 'destroy'),
array($handler, 'gc')
);
}
session_start();
}
Sets or gets flash data.
| Type | Description |
|---|---|
| mixed | (optional) Flash data |
mixed
public static function flash($data = null)
{
if(session_id() === '')
{
Session::start();
}
if($data !== null)
{
$_SESSION[MAKO_APPLICATION_ID . '_flash'] = $data;
}
else
{
if(isset($_SESSION[MAKO_APPLICATION_ID . '_flash']))
{
$data = $_SESSION[MAKO_APPLICATION_ID . '_flash'];
unset($_SESSION[MAKO_APPLICATION_ID . '_flash']);
return $data;
}
else
{
return false;
}
}
}