Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mms] Add method to allow any code to register tasks to run on logout.
- Loading branch information
Showing
4 changed files
with
147 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
/** | ||
* Copyright 2014 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file COPYING for license information (LGPL). If you | ||
* did not receive this file, see http://www.horde.org/licenses/lgpl21. | ||
* | ||
* @category Horde | ||
* @copyright 2014 Horde LLC | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @package Core | ||
*/ | ||
|
||
/** | ||
* Manage the logout tasks registered with Horde_Registry. | ||
* | ||
* @author Michael Slusarz <slusarz@horde.org> | ||
* @category Horde | ||
* @copyright 2014 Horde LLC | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @package Core | ||
* @since 2.13.0 | ||
*/ | ||
class Horde_Registry_Logout | ||
{ | ||
/** Session storage key. */ | ||
const SESSION_KEY = 'registry_logout'; | ||
|
||
/** | ||
* Add a class to the logout queue. | ||
* | ||
* @param mixed $classname The classname to add (or an object of that | ||
* class). The class must be able to be | ||
* instantiated via Horde_Injector and must | ||
* implement the Horde_Registry_Logout_Task | ||
* interface. | ||
*/ | ||
public function add($classname) | ||
{ | ||
$classname = is_object($classname) | ||
? get_class($classname) | ||
: strval($classname); | ||
|
||
$queue = $this->_getTasks(); | ||
|
||
if (!in_array($classname, $queue)) { | ||
$queue[] = $classname; | ||
$this->_setTasks($queue); | ||
} | ||
} | ||
|
||
/** | ||
* Runs the list of logout tasks and clears the queue. | ||
*/ | ||
public function run() | ||
{ | ||
global $injector; | ||
|
||
foreach ($this->_getTasks() as $val) { | ||
try { | ||
$ob = $injector->getInstance($val); | ||
if ($ob instanceof Horde_Registry_Logout_Task) { | ||
$ob->logoutTask(); | ||
} | ||
} catch (Exception $e) {} | ||
} | ||
|
||
$this->_setTasks(array()); | ||
} | ||
|
||
/** | ||
* Return the list of logout tasks. | ||
*/ | ||
private function _getTasks() | ||
{ | ||
global $session; | ||
|
||
return $session->get( | ||
'horde', | ||
self::SESSION_KEY, | ||
$session::TYPE_ARRAY | ||
); | ||
} | ||
|
||
/** | ||
* Set the list of logout tasks. | ||
* | ||
* @param array $queue List of classnames. | ||
*/ | ||
private function _setTasks($queue) | ||
{ | ||
$GLOBALS['session']->set( | ||
'horde', | ||
self::SESSION_KEY, | ||
$queue | ||
); | ||
} | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/** | ||
* Copyright 2014 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file COPYING for license information (LGPL). If you | ||
* did not receive this file, see http://www.horde.org/licenses/lgpl21. | ||
* | ||
* @category Horde | ||
* @copyright 2014 Horde LLC | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @package Core | ||
*/ | ||
|
||
/** | ||
* Interface to register a logout task. | ||
* | ||
* @author Michael Slusarz <slusarz@horde.org> | ||
* @category Horde | ||
* @copyright 2014 Horde LLC | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @package Core | ||
* @since 2.13.0 | ||
*/ | ||
interface Horde_Registry_Logout_Task | ||
{ | ||
/** | ||
* Function to run on logout. | ||
*/ | ||
public function logoutTask(); | ||
|
||
} |
This file contains 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