diff options
author | Gerrit Uitslag <klapinklapin@gmail.com> | 2014-02-23 22:07:26 +0100 |
---|---|---|
committer | Gerrit Uitslag <klapinklapin@gmail.com> | 2014-02-23 22:07:26 +0100 |
commit | 8fcb305db0081dacd8e8ad0583da5ecc6c6837dc (patch) | |
tree | 928fc44fde692835bca9dd304ebcb17cdd710ac8 /inc/events.php | |
parent | 4d5954c8d1f8bcc5450f8cf70d8139cf5a1e697d (diff) | |
parent | 5d873dd4ce31c79403a01ac0e40ff148be282592 (diff) | |
download | rpg-8fcb305db0081dacd8e8ad0583da5ecc6c6837dc.tar.gz rpg-8fcb305db0081dacd8e8ad0583da5ecc6c6837dc.tar.bz2 |
Merge remote-tracking branch 'origin/master' into diff_navigation
Conflicts:
inc/html.php
Diffstat (limited to 'inc/events.php')
-rw-r--r-- | inc/events.php | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/inc/events.php b/inc/events.php index f7b1a7a16..58ba4d5e4 100644 --- a/inc/events.php +++ b/inc/events.php @@ -11,12 +11,12 @@ if(!defined('DOKU_INC')) die('meh.'); class Doku_Event { // public properties - var $name = ''; // READONLY event name, objects must register against this name to see the event - var $data = null; // READWRITE data relevant to the event, no standardised format (YET!) - var $result = null; // READWRITE the results of the event action, only relevant in "_AFTER" advise + public $name = ''; // READONLY event name, objects must register against this name to see the event + public $data = null; // READWRITE data relevant to the event, no standardised format (YET!) + public $result = null; // READWRITE the results of the event action, only relevant in "_AFTER" advise // event handlers may modify this if they are preventing the default action // to provide the after event handlers with event results - var $canPreventDefault = true; // READONLY if true, event handlers can prevent the events default action + public $canPreventDefault = true; // READONLY if true, event handlers can prevent the events default action // private properties, event handlers can effect these through the provided methods var $_default = true; // whether or not to carry out the default action associated with the event @@ -32,6 +32,10 @@ class Doku_Event { } + function __toString() { + return $this->name; + } + /** * advise functions * @@ -117,7 +121,7 @@ class Doku_Event_Handler { // public properties: none // private properties - var $_hooks = array(); // array of events and their registered handlers + protected $_hooks = array(); // array of events and their registered handlers /** * event_handler @@ -148,29 +152,35 @@ class Doku_Event_Handler { * if NULL, method is assumed to be a globally available function * @param $method (function) event handler function * @param $param (mixed) data passed to the event handler + * @param $seq (int) sequence number for ordering hook execution (ascending) */ - function register_hook($event, $advise, $obj, $method, $param=null) { - $this->_hooks[$event.'_'.$advise][] = array($obj, $method, $param); + function register_hook($event, $advise, $obj, $method, $param=null, $seq=0) { + $seq = (int)$seq; + $doSort = !isset($this->_hooks[$event.'_'.$advise][$seq]); + $this->_hooks[$event.'_'.$advise][$seq][] = array($obj, $method, $param); + + if ($doSort) { + ksort($this->_hooks[$event.'_'.$advise]); + } } - function process_event(&$event,$advise='') { + function process_event($event,$advise='') { $evt_name = $event->name . ($advise ? '_'.$advise : '_BEFORE'); if (!empty($this->_hooks[$evt_name])) { - foreach ($this->_hooks[$evt_name] as $hook) { - // list($obj, $method, $param) = $hook; - $obj =& $hook[0]; - $method = $hook[1]; - $param = $hook[2]; - - if (is_null($obj)) { - $method($event, $param); - } else { - $obj->$method($event, $param); - } + foreach ($this->_hooks[$evt_name] as $sequenced_hooks) { + foreach ($sequenced_hooks as $hook) { + list($obj, $method, $param) = $hook; + + if (is_null($obj)) { + $method($event, $param); + } else { + $obj->$method($event, $param); + } - if (!$event->_continue) break; + if (!$event->_continue) return; + } } } } |