mako\Session


Description


Session class.


Class methods


Toggle source

protected __construct()


Protected constructor since this is a static class.

Return value

NULL

protected function __construct()
{
	// Nothing here
}

Toggle source

public static start($name = NULL)


Starts a session using the chosen type of storage.


Parameters

Type Description
string (optional) Session configuration name
Return value

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();
}

Toggle source

public static flash($data = NULL)


Sets or gets flash data.


Parameters

Type Description
mixed (optional) Flash data
Return value

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;
		}
	}
}