示例#1
0
 /**
  * Call all callbacks registered to handle the given hook. Callbacks are called
  * one by one, higher priorities first.
  *
  * @param string $hook_name - Name of the hook
  * @param mixed $params - Parameters that are passed to callback function
  * @return boolean
  */
 public static function call($hook_name, $params = false)
 {
     if (empty(self::$hooks) or empty(self::$hooks[$hook_name])) {
         return true;
     }
     //reset to defaults
     self::$do_default = true;
     self::$propagate_limit = 0;
     self::$return_status = true;
     self::$current_priority = 0;
     // get priorities, higher first
     $p = array_keys(self::$hooks[$hook_name]);
     rsort($p, SORT_NUMERIC);
     // process callbacks in order of priorities
     foreach ($p as $priority) {
         self::$current_priority = $priority;
         if (!isset(self::$hooks[$hook_name][$priority])) {
             //skip empty
             continue;
         }
         foreach (self::$hooks[$hook_name][$priority] as $callback) {
             if (empty($callback) or empty($callback['enabled'])) {
                 //skip disabled or not set
                 continue;
             }
             if ($priority <= self::$propagate_limit) {
                 // stop further propagation
                 break 2;
             }
             // call handler function
             if (!file_exists(VIVVO_FS_INSTALL_ROOT . $callback['filename'])) {
                 continue;
             }
             require_once VIVVO_FS_INSTALL_ROOT . $callback['filename'];
             if ($callback['class']) {
                 if (!method_exists($callback['class'], $callback['function'])) {
                     continue;
                 }
                 $func = array($callback['class'], $callback['function']);
             } else {
                 $func = $callback['function'];
                 if (!function_exists($func)) {
                     continue;
                 }
             }
             // do the call
             call_user_func_array($func, array($hook_name, &$params));
         }
     }
     return self::$do_default;
 }