mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-02-06 15:14:58 +00:00
run hook preRun, postRun before and after controller, check for hooks of parent class
This commit is contained in:
parent
7576bee235
commit
a02afe4e64
|
@ -54,6 +54,7 @@ class SeedDMS_Controller_Common {
|
|||
* @return mixed return value of called method
|
||||
*/
|
||||
function __invoke($get=array()) {
|
||||
$this->callHook('preRun', isset($get['action']) ? $get['action'] : 'run');
|
||||
if(isset($get['action']) && $get['action']) {
|
||||
if(method_exists($this, $get['action'])) {
|
||||
return $this->{$get['action']}();
|
||||
|
@ -63,6 +64,7 @@ class SeedDMS_Controller_Common {
|
|||
}
|
||||
} else
|
||||
return $this->run();
|
||||
$this->callHook('postRun', isset($get['action']) ? $get['action'] : 'run');
|
||||
}
|
||||
|
||||
function setParams($params) {
|
||||
|
@ -188,10 +190,17 @@ class SeedDMS_Controller_Common {
|
|||
* null if no hook was called
|
||||
*/
|
||||
function callHook($hook) { /* {{{ */
|
||||
$tmps = array();
|
||||
$tmp = explode('_', get_class($this));
|
||||
if(isset($GLOBALS['SEEDDMS_HOOKS']['controller'][lcfirst($tmp[2])])) {
|
||||
$tmps[] = $tmp[2];
|
||||
$tmp = explode('_', get_parent_class($this));
|
||||
$tmps[] = $tmp[2];
|
||||
/* Run array_unique() in case the parent class has the same suffix */
|
||||
$tmps = array_unique($tmps);
|
||||
foreach($tmps as $tmp)
|
||||
if(isset($GLOBALS['SEEDDMS_HOOKS']['controller'][lcfirst($tmp)])) {
|
||||
$this->lasthookresult = null;
|
||||
foreach($GLOBALS['SEEDDMS_HOOKS']['controller'][lcfirst($tmp[2])] as $hookObj) {
|
||||
foreach($GLOBALS['SEEDDMS_HOOKS']['controller'][lcfirst($tmp)] as $hookObj) {
|
||||
if (method_exists($hookObj, $hook)) {
|
||||
switch(func_num_args()) {
|
||||
case 3:
|
||||
|
|
Loading…
Reference in New Issue
Block a user