miniMVC/sys/libraries/session.php

83 lines
1.4 KiB
PHP
Raw Normal View History

2012-05-03 13:26:09 -04:00
<?php
/**
* MiniMVC
*
* Convention-based micro-framework for PHP
*
* @package miniMVC
* @author Timothy J. Warren
* @copyright Copyright (c) 2011 - 2012
* @link https://github.com/timw4mail/miniMVC
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* Class to improve handling of PHP sessions
*
* @package miniMVC
* @subpackage Libraries
*/
class MM_Session{
use JSObject, Singleton
{
Singleton::__invoke insteadof JSObject;
}
/**
* Start a session
*/
protected function __construct()
{
session_start();
/**
* Define a unique id for this session
*/
define('SESS_ID', uniqid(uniqid(), TRUE));
$_SESSION[SESS_ID] = array();
}
// --------------------------------------------------------------------------
/**
* Set a session value
*
* @param string $key
* @param mixed $val
* @return void
*/
public function __set($key, $val)
{
$_SESSION[SESS_ID][$key] = $val;
}
// --------------------------------------------------------------------------
/**
* Retreive a session value
*
* @param string $key
* @return mixed
*/
public function __get($key)
{
return $_SESSION[SESS_ID][$key];
}
// --------------------------------------------------------------------------
/**
* Destroy a session
*
* @return void
*/
public function destroy()
{
sess_destroy();
}
}
// End of php_session.php