Beispiel #1
0
 /**
  * call a trigger
  * @param string $trigger_name trigger's name to call
  * @param string $called_position called position
  * @param object $obj an object as a parameter to trigger
  * @return Object
  * */
 public static function triggerCall($trigger_name, $called_position, &$obj)
 {
     // skip if not installed
     if (!Context::isInstalled()) {
         return new Object();
     }
     $oModuleModel = getModel('module');
     $triggers = $oModuleModel->getTriggers($trigger_name, $called_position);
     if (!$triggers) {
         $triggers = array();
     }
     //store before trigger call time
     $before_trigger_time = microtime(true);
     foreach ($triggers as $item) {
         $module = $item->module;
         $type = $item->type;
         $called_method = $item->called_method;
         // todo why don't we call a normal class object ?
         $oModule = getModule($module, $type);
         if (!$oModule || !method_exists($oModule, $called_method)) {
             continue;
         }
         // do not call if module is blacklisted
         if (Context::isBlacklistedPlugin($oModule->module)) {
             continue;
         }
         $before_each_trigger_time = microtime(true);
         $output = $oModule->{$called_method}($obj);
         $after_each_trigger_time = microtime(true);
         if ($trigger_name !== 'common.flushDebugInfo') {
             $trigger_target = $module . ($type === 'class' ? '' : $type) . '.' . $called_method;
             Rhymix\Framework\Debug::addTrigger(array('name' => $trigger_name . '.' . $called_position, 'target' => $trigger_target, 'target_plugin' => $module, 'elapsed_time' => $after_each_trigger_time - $before_each_trigger_time));
         }
         if (is_object($output) && method_exists($output, 'toBool') && !$output->toBool()) {
             return $output;
         }
         unset($oModule);
     }
     $trigger_functions = $oModuleModel->getTriggerFunctions($trigger_name, $called_position);
     foreach ($trigger_functions as $item) {
         $before_each_trigger_time = microtime(true);
         $output = $item($obj);
         $after_each_trigger_time = microtime(true);
         if ($trigger_name !== 'common.writeSlowlog') {
             if (is_string($item)) {
                 $trigger_target = $item;
             } elseif (is_array($item) && count($item)) {
                 if (is_object($item[0])) {
                     $trigger_target = get_class($item[0]) . '.' . strval($item[1]);
                 } else {
                     $trigger_target = implode('.', $item);
                 }
             } else {
                 $trigger_target = 'closure';
             }
             Rhymix\Framework\Debug::addTrigger(array('name' => $trigger_name . '.' . $called_position, 'target' => $trigger_target, 'target_plugin' => null, 'elapsed_time' => $after_each_trigger_time - $before_each_trigger_time));
         }
         if (is_object($output) && method_exists($output, 'toBool') && !$output->toBool()) {
             return $output;
         }
     }
     return new Object();
 }