Skip to content
Snippets Groups Projects
Commit 9be65c6b authored by Peter Rotich's avatar Peter Rotich Committed by Peter Rotich
Browse files

Make list of subsribers static and private

parent 8c385edb
No related branches found
No related tags found
No related merge requests found
......@@ -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();
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment