aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-11-13 15:14:02 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-11-13 15:14:02 +0000
commit72f2eda02e39b4a49c5683f66b86b19bed9196a5 (patch)
tree5b37d929bd127328ada56657bc1641f6c9b638d5 /engine
parentbb71b79f72db01331088beca1aac8c488b65bae5 (diff)
downloadelgg-72f2eda02e39b4a49c5683f66b86b19bed9196a5.tar.gz
elgg-72f2eda02e39b4a49c5683f66b86b19bed9196a5.tar.bz2
Experimental ElggCache
git-svn-id: https://code.elgg.org/elgg/trunk@2446 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/sessions.php75
1 files changed, 74 insertions, 1 deletions
diff --git a/engine/lib/sessions.php b/engine/lib/sessions.php
index 02a3e06ca..bd9ce9d31 100644
--- a/engine/lib/sessions.php
+++ b/engine/lib/sessions.php
@@ -10,7 +10,76 @@
* @author Curverider Ltd
* @copyright Curverider Ltd 2008
* @link http://elgg.org/
- */
+ */
+
+ /** Elgg magic session */
+ static $SESSION;
+
+ /**
+ * Magic session class.
+ * This class is intended to extend the $_SESSION magic variable by providing an API hook
+ * to plug in other values.
+ *
+ * Primarily this is intended to provide a way of supplying "logged in user" details without touching the session
+ * (which can cause problems when accessed server side).
+ *
+ * If a value is present in the session then that value is returned, otherwise a plugin hook 'session::get', '$var' is called,
+ * where $var is the variable being requested.
+ *
+ * Setting values will store variables in the session in the normal way.
+ *
+ * This is EXPERIMENTAL.
+ */
+ class ElggSession implements ArrayAccess
+ {
+ /** Local cache of trigger retrieved variables */
+ private static $__localcache;
+
+ /** Set a value, go straight to session. */
+ function offsetSet($key, $value) { $_SESSION[$key] = $value; }
+
+ /**
+ * Get a variable from either the session, or if its not in the session attempt to get it from
+ * an api call.
+ */
+ function offsetGet($key)
+ {
+ if (isset($_SESSION[$key]))
+ return $_SESSION[$key];
+
+ if (isset($this->__localcache[$key]))
+ return $this->__localcache[$key];
+
+ $value = null;
+ $value = trigger_plugin_hook('session::get', $key, null, $value);
+
+ if (!$this->__localcache)
+ $this->__localcache = array();
+
+ $this->__localcache[$key] = $value;
+
+ return $this->__localcache[$key];
+ }
+
+ /**
+ * Unset a value from the cache and the session.
+ */
+ function offsetUnset($key)
+ {
+ unset($this->__localcache[$key]);
+ unset($_SESSION[$key]);
+ }
+
+ /**
+ * Return whether the value is set in either the session or the cache.
+ */
+ function offsetExists($offset) {
+ if (isset($this->__localcache[$key]))
+ return true;
+
+ return isset($_SESSION[$key]);
+ }
+ }
/**
* Returns whether or not the user is currently logged in
@@ -263,6 +332,10 @@
// Register a default PAM handler
register_pam_handler('pam_auth_userpass');
+
+ // Initialise the magic session
+ static $SESSION;
+ $SESSION = new ElggSession();
return true;