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 @@ ...@@ -25,6 +25,8 @@
* the codebase there exists a Signal::send() for the same named signal. * the codebase there exists a Signal::send() for the same named signal.
*/ */
class Signal { class Signal {
static private $subscribers = array();
/** /**
* Subscribe to a signal. * Subscribe to a signal.
* *
...@@ -51,10 +53,9 @@ class Signal { ...@@ -51,10 +53,9 @@ class Signal {
* signal handler. The function will receive the signal data and should * signal handler. The function will receive the signal data and should
* return true if the signal handler should be called. * 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) { $check=null) {
global $_subscribers; if (!isset(self::$subscribers[$signal])) self::$subscribers[$signal] = array();
if (!isset($_subscribers[$signal])) $_subscribers[$signal] = array();
// XXX: Ensure $object if set is a class // XXX: Ensure $object if set is a class
if ($object && !is_string($object)) if ($object && !is_string($object))
trigger_error("Invalid object: $object: Expected class"); trigger_error("Invalid object: $object: Expected class");
...@@ -62,7 +63,7 @@ class Signal { ...@@ -62,7 +63,7 @@ class Signal {
trigger_error("Invalid check function: Must be callable"); trigger_error("Invalid check function: Must be callable");
$check = null; $check = null;
} }
$_subscribers[$signal][] = array($object, $callable, $check); self::$subscribers[$signal][] = array($object, $callable, $check);
} }
/** /**
...@@ -85,11 +86,10 @@ class Signal { ...@@ -85,11 +86,10 @@ class Signal {
* possible to propogate changes in the signal handlers back to the * possible to propogate changes in the signal handlers back to the
* originating context. * originating context.
*/ */
/*static*/ function send($signal, $object, &$data=null) { static function send($signal, $object, &$data=null) {
global $_subscribers; if (!isset(self::$subscribers[$signal]))
if (!isset($_subscribers[$signal]))
return; return;
foreach ($_subscribers[$signal] as $sub) { foreach (self::$subscribers[$signal] as $sub) {
list($s, $callable, $check) = $sub; list($s, $callable, $check) = $sub;
if ($s && !is_a($object, $s)) if ($s && !is_a($object, $s))
continue; continue;
...@@ -99,6 +99,4 @@ class Signal { ...@@ -99,6 +99,4 @@ class Signal {
} }
} }
} }
$_subscribers = array();
?> ?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment