Elgg  Version 1.9
EventsService.php
Go to the documentation of this file.
1 <?php
2 
13 
14  const OPTION_STOPPABLE = 'stoppable';
15  const OPTION_DEPRECATION_MESSAGE = 'deprecation_message';
16  const OPTION_DEPRECATION_VERSION = 'deprecation_version';
17 
25  public function trigger($event, $type, $object = null, array $options = array()) {
26  $options = array_merge(array(
27  self::OPTION_STOPPABLE => true,
28  self::OPTION_DEPRECATION_MESSAGE => '',
29  self::OPTION_DEPRECATION_VERSION => '',
30  ), $options);
31 
32  $events = $this->hasHandler($event, $type);
33  if ($events && $options[self::OPTION_DEPRECATION_MESSAGE]) {
35  $options[self::OPTION_DEPRECATION_MESSAGE],
36  $options[self::OPTION_DEPRECATION_VERSION],
37  2
38  );
39  }
40 
41  $events = $this->getOrderedHandlers($event, $type);
42  $args = array($event, $type, $object);
43 
44  foreach ($events as $callback) {
45  if (!is_callable($callback)) {
46  if ($this->logger) {
47  $this->logger->warn("handler for event [$event, $type] is not callable: "
48  . $this->describeCallable($callback));
49  }
50  continue;
51  }
52 
53  $return = call_user_func_array($callback, $args);
54  if (!empty($options[self::OPTION_STOPPABLE]) && ($return === false)) {
55  return false;
56  }
57  }
58 
59  return true;
60  }
61 }
describeCallable($callable)
Get a string description of a callback.
$object
Definition: upgrade.php:12
trigger($event, $type, $object=null, array $options=array())
Triggers an Elgg event.
$return
Definition: opendd.php:15
$args
Some servers don&#39;t allow PHP to check the rewrite, so try via AJAX.
$options
Definition: index.php:14
const OPTION_DEPRECATION_MESSAGE
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Sends a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1171
$type
Definition: add.php:8
hasHandler($name, $type)
Does the hook have a handler?
const OPTION_DEPRECATION_VERSION
getOrderedHandlers($name, $type)
Returns an ordered array of handlers registered for $name and $type.