diff options
author | Andreas Gohr <andi@splitbrain.org> | 2014-02-16 18:12:53 +0100 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2014-02-16 18:12:53 +0100 |
commit | db7110fa511e3e49024e8e2b11408a9457c42efb (patch) | |
tree | f1c0282af8574a8950dfce3cd4b3611e0818f4d3 /inc | |
parent | 7e9cad7a2f9ee29515332f3569c056e545c35951 (diff) | |
parent | b95f73d374c43006a82eddd35b630bd10a9fbb5f (diff) | |
download | rpg-db7110fa511e3e49024e8e2b11408a9457c42efb.tar.gz rpg-db7110fa511e3e49024e8e2b11408a9457c42efb.tar.bz2 |
Merge pull request #552 from splitbrain/event_handler_sequencing
Add ordering to event handlers
Diffstat (limited to 'inc')
-rw-r--r-- | inc/events.php | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/inc/events.php b/inc/events.php index f7b1a7a16..9c3169b34 100644 --- a/inc/events.php +++ b/inc/events.php @@ -148,9 +148,10 @@ 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) { + $this->_hooks[$event.'_'.$advise][] = array($obj, $method, $param, (int)$seq); } function process_event(&$event,$advise='') { @@ -158,8 +159,8 @@ class Doku_Event_Handler { $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; + foreach ($this->sort_hooks($this->_hooks[$evt_name]) as $hook) { + // list($obj, $method, $param, $seq) = $hook; $obj =& $hook[0]; $method = $hook[1]; $param = $hook[2]; @@ -174,6 +175,20 @@ class Doku_Event_Handler { } } } + + protected function sort_hooks($hooks) { + usort($hooks, array('Doku_Event_Handler','cmp_hooks')); + return $hooks; + } + + public static function cmp_hooks($a, $b) { + if ($a[3] == $b[3]) { + return 0; + } + + return ($a[3] < $b[3]) ? -1 : 1; + } + } /** |