Added comments
This commit is contained in:
parent
81de09711b
commit
ae8cfe6569
1 changed files with 15 additions and 7 deletions
22
lib/hook.php
22
lib/hook.php
|
@ -20,19 +20,22 @@ class OC_Hook{
|
|||
* TODO: write example
|
||||
*/
|
||||
static public function connect( $signalclass, $signalname, $slotclass, $slotname ) {
|
||||
// Create the data structure
|
||||
// If we're trying to connect to an emitting class that isn't
|
||||
// yet registered, register it
|
||||
if( !array_key_exists( $signalclass, self::$registered )) {
|
||||
self::$registered[$signalclass] = array();
|
||||
}
|
||||
if( !array_key_exists( $signalname, self::$registered[$signalclass] )) {
|
||||
// If we're trying to connect to an emitting method that isn't
|
||||
// yet registered, register it with the emitting class
|
||||
if( !array_key_exists( $signalname, self::$registered[$signalclass] )) {
|
||||
self::$registered[$signalclass][$signalname] = array();
|
||||
}
|
||||
|
||||
// register hook
|
||||
|
||||
// Connect the hook handler to the requested emitter
|
||||
self::$registered[$signalclass][$signalname][] = array(
|
||||
"class" => $slotclass,
|
||||
"name" => $slotname );
|
||||
|
||||
|
||||
// No chance for failure ;-)
|
||||
return true;
|
||||
}
|
||||
|
@ -49,14 +52,19 @@ class OC_Hook{
|
|||
* TODO: write example
|
||||
*/
|
||||
static public function emit( $signalclass, $signalname, $params = array()) {
|
||||
// Return false if there are no slots
|
||||
|
||||
// Return false if no hook handlers are listening to this
|
||||
// emitting class
|
||||
if( !array_key_exists( $signalclass, self::$registered )) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return false if no hook handlers are listening to this
|
||||
// emitting method
|
||||
if( !array_key_exists( $signalname, self::$registered[$signalclass] )) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Call all slots
|
||||
foreach( self::$registered[$signalclass][$signalname] as $i ) {
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue