Created
September 28, 2011 07:04
-
-
Save jwdunne/1247199 to your computer and use it in GitHub Desktop.
Namespaced Sessions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
/** | |
* Session Class | |
*/ | |
class Session { | |
private $namespace; | |
public static function init($namespace) { | |
return new Session($namespace); | |
} | |
public function __construct($namespace) { | |
$this->namespace = $namespace; | |
} | |
public function __get($name) { | |
$key = $this->createKey($name); | |
if (isset($_SESSION[$key])) { | |
return $_SESSION[$key]; | |
} | |
} | |
public function __isset($name) { | |
$key = $this->createKey($name); | |
return isset($_SESSION[$key]); | |
} | |
public function __set($name, $value) { | |
$key = $this->createKey($name); | |
$_SESSION[$key] = $value; | |
} | |
private function createKey($name) { | |
return $this->namespace.$name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment