Example #1
0
 /**
  * Triggers a plugin hook
  *
  * @see elgg_trigger_plugin_hook
  * @access private
  */
 public function trigger($hook, $type, $params = null, $returnvalue = null)
 {
     $hooks = $this->getOrderedHandlers($hook, $type);
     foreach ($hooks as $callback) {
         if (!is_callable($callback)) {
             if ($this->logger) {
                 $inspector = new Inspector();
                 $this->logger->warn("handler for plugin hook [{$hook}, {$type}] is not callable: " . $inspector->describeCallable($callback));
             }
             continue;
         }
         $exit_warning = function () use($hook, $type, $callback) {
             $inspector = new Inspector();
             elgg_deprecated_notice("'{$hook}', '{$type}' plugin hook should not be used to serve a response. Instead return an " . "appropriate ResponseBuilder instance from an action or page handler. Do not terminate " . "code execution with exit() or die() in {$inspector->describeCallable($callback)}", '2.3');
         };
         if (in_array($hook, ['forward', 'action', 'route'])) {
             _elgg_services()->events->registerHandler('shutdown', 'system', $exit_warning);
         }
         $args = array($hook, $type, $returnvalue, $params);
         $temp_return_value = call_user_func_array($callback, $args);
         if (!is_null($temp_return_value)) {
             $returnvalue = $temp_return_value;
         }
         if (in_array($hook, ['forward', 'action', 'route'])) {
             _elgg_services()->events->unregisterHandler('shutdown', 'system', $exit_warning);
         }
     }
     return $returnvalue;
 }
Example #2
0
 /**
  * Triggers an Elgg event.
  * 
  * @see elgg_trigger_event
  * @see elgg_trigger_after_event
  * @access private
  */
 public function trigger($event, $type, $object = null, array $options = array())
 {
     $options = array_merge(array(self::OPTION_STOPPABLE => true, self::OPTION_DEPRECATION_MESSAGE => '', self::OPTION_DEPRECATION_VERSION => ''), $options);
     $events = $this->hasHandler($event, $type);
     if ($events && $options[self::OPTION_DEPRECATION_MESSAGE]) {
         elgg_deprecated_notice($options[self::OPTION_DEPRECATION_MESSAGE], $options[self::OPTION_DEPRECATION_VERSION], 2);
     }
     $events = $this->getOrderedHandlers($event, $type);
     $args = array($event, $type, $object);
     foreach ($events as $callback) {
         if (!is_callable($callback)) {
             if ($this->logger) {
                 $this->logger->warn("handler for event [{$event}, {$type}] is not callable: " . $this->inspector->describeCallable($callback));
             }
             continue;
         }
         if ($this->timer && $type === 'system' && $event !== 'shutdown') {
             $callback_as_string = $this->inspector->describeCallable($callback) . "()";
             $this->timer->begin(["[{$event},{$type}]", $callback_as_string]);
             $return = call_user_func_array($callback, $args);
             $this->timer->end(["[{$event},{$type}]", $callback_as_string]);
         } else {
             $return = call_user_func_array($callback, $args);
         }
         if (!empty($options[self::OPTION_STOPPABLE]) && $return === false) {
             return false;
         }
     }
     return true;
 }
Example #3
0
 /**
  * Triggers a plugin hook
  *
  * @see elgg_trigger_plugin_hook
  * @access private
  */
 public function trigger($hook, $type, $params = null, $returnvalue = null)
 {
     $hooks = $this->getOrderedHandlers($hook, $type);
     foreach ($hooks as $callback) {
         if (!is_callable($callback)) {
             if ($this->logger) {
                 $inspector = new Inspector();
                 $this->logger->warn("handler for plugin hook [{$hook}, {$type}] is not callable: " . $inspector->describeCallable($callback));
             }
             continue;
         }
         $args = array($hook, $type, $returnvalue, $params);
         $temp_return_value = call_user_func_array($callback, $args);
         if (!is_null($temp_return_value)) {
             $returnvalue = $temp_return_value;
         }
     }
     return $returnvalue;
 }
Example #4
0
 /**
  * Triggers an Elgg event.
  * 
  * @see elgg_trigger_event
  * @see elgg_trigger_after_event
  * @access private
  */
 public function trigger($event, $type, $object = null, array $options = array())
 {
     $options = array_merge(array(self::OPTION_STOPPABLE => true, self::OPTION_DEPRECATION_MESSAGE => '', self::OPTION_DEPRECATION_VERSION => ''), $options);
     $events = $this->hasHandler($event, $type);
     if ($events && $options[self::OPTION_DEPRECATION_MESSAGE]) {
         elgg_deprecated_notice($options[self::OPTION_DEPRECATION_MESSAGE], $options[self::OPTION_DEPRECATION_VERSION], 2);
     }
     $events = $this->getOrderedHandlers($event, $type);
     $args = array($event, $type, $object);
     foreach ($events as $callback) {
         if (!is_callable($callback)) {
             if ($this->logger) {
                 $inspector = new Inspector();
                 $this->logger->warn("handler for event [{$event}, {$type}] is not callable: " . $inspector->describeCallable($callback));
             }
             continue;
         }
         $return = call_user_func_array($callback, $args);
         if (!empty($options[self::OPTION_STOPPABLE]) && $return === false) {
             return false;
         }
     }
     return true;
 }