diff --git a/inc/Extension/Event.php b/inc/Extension/Event.php index 9893fd4558..bbaa52e55d 100644 --- a/inc/Extension/Event.php +++ b/inc/Extension/Event.php @@ -1,4 +1,5 @@ name = $name; $this->data =& $data; - } /** @@ -43,9 +48,7 @@ public function __toString() } /** - * advise functions - * - * advise all registered handlers of this event + * advise all registered BEFORE handlers of this event * * if these methods are used by functions outside of this object, they must * properly handle correct processing of any default action and issue an @@ -58,32 +61,38 @@ public function __toString() * unset($evt); * * @param bool $enablePreventDefault - * @return bool results of processing the event, usually $this->_default + * @return bool results of processing the event, usually $this->runDefault */ public function advise_before($enablePreventDefault = true) { global $EVENT_HANDLER; $this->canPreventDefault = $enablePreventDefault; - if($EVENT_HANDLER !== null) { + if ($EVENT_HANDLER !== null) { $EVENT_HANDLER->process_event($this, 'BEFORE'); } else { - dbglog($this->name.':BEFORE event triggered before event system was initialized'); + dbglog($this->name . ':BEFORE event triggered before event system was initialized'); } - return (!$enablePreventDefault || $this->_default); + return (!$enablePreventDefault || $this->runDefault); } + /** + * advise all registered AFTER handlers of this event + * + * @param bool $enablePreventDefault + * @see advise_before() for details + */ public function advise_after() { global $EVENT_HANDLER; - $this->_continue = true; + $this->mayContinue = true; - if($EVENT_HANDLER !== null) { + if ($EVENT_HANDLER !== null) { $EVENT_HANDLER->process_event($this, 'AFTER'); } else { - dbglog($this->name.':AFTER event triggered before event system was initialized'); + dbglog($this->name . ':AFTER event triggered before event system was initialized'); } } @@ -107,7 +116,7 @@ public function trigger($action = null, $enablePrevent = true) if (!is_callable($action)) { $enablePrevent = false; - if (!is_null($action)) { + if ($action !== null) { trigger_error( 'The default action of ' . $this . ' is not null but also not callable. Maybe the method is not public?', @@ -138,7 +147,7 @@ public function trigger($action = null, $enablePrevent = true) */ public function stopPropagation() { - $this->_continue = false; + $this->mayContinue = false; } /** @@ -148,7 +157,7 @@ public function stopPropagation() */ public function mayPropagate() { - return $this->_continue; + return $this->mayContinue; } /** @@ -158,7 +167,7 @@ public function mayPropagate() */ public function preventDefault() { - $this->_default = false; + $this->runDefault = false; } /** @@ -168,7 +177,7 @@ public function preventDefault() */ public function mayRunDefault() { - return $this->_default; + return $this->runDefault; } /** @@ -176,16 +185,17 @@ public function mayRunDefault() * * Creates, triggers and destroys an event in one go * - * @param string $name name for the event - * @param mixed $data event data - * @param callable $action (optional, default=NULL) default action, a php callback function - * @param bool $canPreventDefault (optional, default=true) can hooks prevent the default action + * @param string $name name for the event + * @param mixed $data event data + * @param callable $action (optional, default=NULL) default action, a php callback function + * @param bool $canPreventDefault (optional, default=true) can hooks prevent the default action * * @return mixed the event results value after all event processing is complete * by default this is the return value of the default action however * it can be set or modified by event handler hooks */ - static public function createAndTrigger($name, &$data, $action=null, $canPreventDefault=true) { + static public function createAndTrigger($name, &$data, $action = null, $canPreventDefault = true) + { $evt = new Event($name, $data); return $evt->trigger($action, $canPreventDefault); }