예제 #1
0
파일: Hooks.php 프로젝트: LobbyOS/server
 /**
  * doActionRefArray Execute functions hooked on a specific action hook, specifying arguments in an array.
  * @access public
  * @since 0.1
  * @param string $tag The name of the action to be executed.
  * @param array $args The arguments supplied to the functions hooked to <tt>$tag</tt>
  * @return null Will return null if $tag does not exist in $filter array
  */
 public static function doActionRefArray($tag, $args)
 {
     if (!isset(self::$actions)) {
         self::$actions = array();
     }
     if (!isset(self::$actions[$tag])) {
         self::$actions[$tag] = 1;
     } else {
         ++self::$actions[$tag];
     }
     // Do 'all' actions first
     if (isset(self::$filters['all'])) {
         self::$currentFilter[] = $tag;
         $all_args = func_get_args();
         self::$__callAllHook($all_args);
     }
     if (!isset(self::$filters[$tag])) {
         if (isset(self::$filters['all'])) {
             array_pop(self::$currentFilter);
         }
         return;
     }
     if (!isset(self::$filters['all'])) {
         self::$currentFilter[] = $tag;
     }
     // Sort
     if (!isset($mergedFilters[$tag])) {
         ksort(self::$filters[$tag]);
         $mergedFilters[$tag] = true;
     }
     reset(self::$filters[$tag]);
     do {
         foreach ((array) current(self::$filters[$tag]) as $the_) {
             if (!is_null($the_['function'])) {
                 call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
             }
         }
     } while (next(self::$filters[$tag]) !== false);
     array_pop(self::$currentFilter);
 }