* @license PHP License * @package Wombat * @subpackage content */ /** * Load classes */ WBClass::load('WBUser' , 'WBUser_Auth' ); /** * User Session Data * * Session data connected to currently logged in user. Automatically clear data on * logout * * @version 0.1.0 * @package Wombat * @subpackage content */ class WBUser_Session extends WBStdClass { const PREFIX = 'wb.user.sess.'; /** * session object * @var patSession_Storage */ private $sess; /** * Constructor * * Start session */ public function __construct() { $this->sess = WBClass::create('patSession'); } /** * Has session var * * @see patSession_Storage::has() * @param string $name * @return bool */ public function has($name) { return $this->sess->has(self::PREFIX . $name); } /** * Get session var * * @see patSession_Storage::get() * @param string $name * @return mixed session variable */ public function get($name) { return $this->sess->get(self::PREFIX . $name); } /** * Set session var * * @see patSession_Storage::set() * @param string $name * @param mixed $value * @return bool true on success */ public function set($name, $value) { return $this->sess->set(self::PREFIX . $name, $value); } /** * Clear session var * * @see patSession_Storage::clear() * @param string $name * @return mixed old session value, if set */ public function clear($name) { return $this->sess->clear(self::PREFIX . $name); } /** * Things to do on login * * @see WBUser_Auth::login() */ public function onLogin() { } /** * Things to do on login * * Clear all session vars with prefix * * @see WBUser_Auth::logout() */ public function onLogout() { foreach ($this->sess as $k => $v) { if (0 == strncmp($k, self::PREFIX, strlen(self::PREFIX))) { $this->sess->clear($k); } } } }