diff --git a/include/class.signal.php b/include/class.signal.php index 928c15c4d2392ae767a0c465b6730d859f3dc85f..424ccccc9665a36db41bb5a1ff271150d946ec82 100644 --- a/include/class.signal.php +++ b/include/class.signal.php @@ -25,6 +25,8 @@ * the codebase there exists a Signal::send() for the same named signal. */ class Signal { + static private $subscribers = array(); + /** * Subscribe to a signal. * @@ -51,10 +53,9 @@ class Signal { * signal handler. The function will receive the signal data and should * return true if the signal handler should be called. */ - /*static*/ function connect($signal, $callable, $object=null, + static function connect($signal, $callable, $object=null, $check=null) { - global $_subscribers; - if (!isset($_subscribers[$signal])) $_subscribers[$signal] = array(); + if (!isset(self::$subscribers[$signal])) self::$subscribers[$signal] = array(); // XXX: Ensure $object if set is a class if ($object && !is_string($object)) trigger_error("Invalid object: $object: Expected class"); @@ -62,7 +63,7 @@ class Signal { trigger_error("Invalid check function: Must be callable"); $check = null; } - $_subscribers[$signal][] = array($object, $callable, $check); + self::$subscribers[$signal][] = array($object, $callable, $check); } /** @@ -85,11 +86,10 @@ class Signal { * possible to propogate changes in the signal handlers back to the * originating context. */ - /*static*/ function send($signal, $object, &$data=null) { - global $_subscribers; - if (!isset($_subscribers[$signal])) + static function send($signal, $object, &$data=null) { + if (!isset(self::$subscribers[$signal])) return; - foreach ($_subscribers[$signal] as $sub) { + foreach (self::$subscribers[$signal] as $sub) { list($s, $callable, $check) = $sub; if ($s && !is_a($object, $s)) continue; @@ -99,6 +99,4 @@ class Signal { } } } - -$_subscribers = array(); ?>