<?php
/* Please see the README and LICENSE files. */
/**
* This registers a shutdown function which is called when the system is exiting
* Has a queue of last-minute things
*/
class System_Shutdown implements System_Component {
/**
* Queue of things to do when shutting down
* In the format:
* array("class_name","method","param 1",...,"param n")
*
* @var String[][]
*/
protected static $queue = array();
public static $triggered = false;
/**
* @see System_Component
*/
public function start() {
return register_shutdown_function(array(__CLASS__, "shutdown"));
}
/**
* @see System_Component
*/
public function stop() {
}
/**
* This is what is called byt the system
*/
public static function shutdown() {
self::$triggered = true;
self::do_queue();
}
/**
* This calles each element of the internal queue
*/
protected static function do_queue() {
if (is_array(self::$queue)) {
foreach (self::$queue as $request) {
if (is_array($request)) {
if (class_exists($request[0])) {
if (method_exists($request[0], $request[1])) {
call_user_func_array(array(array_shift($request), array_shift($request)), $request);
}
}
}
}
}
}
/**
* Add a shutdown function to the queue
* @param String $class The class name
* @param String $method The method name
* @param Mixed $param1... The first...param....
*/
public static function add($class, $method) {
self::$queue[] = func_get_args();
}
}
?>