From 8bbeebf795f6d69224ac26a0badba669739bb884 Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Thu, 27 Mar 2008 15:33:15 +0000 Subject: [PATCH] Session: Added logout handler code. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@450 44740490-163a-0410-bde0-09ae8108e29a --- lib/SimpleSAML/Session.php | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/lib/SimpleSAML/Session.php b/lib/SimpleSAML/Session.php index ac27693de..997f8d3a2 100644 --- a/lib/SimpleSAML/Session.php +++ b/lib/SimpleSAML/Session.php @@ -62,6 +62,13 @@ class SimpleSAML_Session implements SimpleSAML_ModifiedInfo { private $dirty = false; + /** + * This is an array of registered logout handlers. + * All registered logout handlers will be called on logout. + */ + private $logout_handlers = array(); + + /** * private constructor restricts instantiaton to getInstance() */ @@ -329,6 +336,9 @@ class SimpleSAML_Session implements SimpleSAML_ModifiedInfo { if ($auth) { $this->sessionstarted = time(); + } else { + /* Call logout handlers. */ + $this->callLogoutHandlers(); } } @@ -430,6 +440,39 @@ class SimpleSAML_Session implements SimpleSAML_ModifiedInfo { $s = serialize($this); return strlen($s); } + + + /** + * This function registers a logout handler. + * + * @param $file The file which contains the logout handler. + * @param $classname The class which contains the logout handler. + * @param $functionname The logout handler function. + */ + public function registerLogoutHandler($file, $classname, $functionname) { + $this->logout_handlers[] = array('file' => $file, 'class' => $classname, 'function' => $functionname); + } + + + /** + * This function calls all registered logout handlers. + */ + private function callLogoutHandlers() { + foreach($this->logout_handlers as $handler) { + + /* Load the file with the logout handler. */ + require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . $handler['file']); + + /* Call the logout handler. */ + $classname = $handler['class']; + $functionname = $handler['function']; + call_user_func(array($classname, $functionname)); + } + + /* We require the logout handlers to register themselves again if they want to be called later. */ + $this->logout_handlers = array(); + } + } ?> \ No newline at end of file -- GitLab