From 8ceb8d1e6ac0ca2d35554d913db705acfe32f2ca Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Fri, 29 Jul 2022 21:37:59 +0200 Subject: [PATCH] get action from request, run hook preRun and check for return value --- inc/inc.ClassControllerCommon.php | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/inc/inc.ClassControllerCommon.php b/inc/inc.ClassControllerCommon.php index 947f45bb8..735b82de8 100644 --- a/inc/inc.ClassControllerCommon.php +++ b/inc/inc.ClassControllerCommon.php @@ -48,24 +48,38 @@ class SeedDMS_Controller_Common { } /** - * Call methods with name in $get['action'] + * Call method with name in $get['action'] * - * @params array $get $_GET or $_POST variables + * Until 5.1.26 (6.0.19) this method took the name of the + * controller method to run from the element 'action' passed + * in the array $get. Since 5.1.27 (6.0.20) a PSR7 Request + * object is available in the controller and used to get the + * action. + * + * @params array $get $_GET or $_POST variables (since 5.1.27 this is no longer used) * @return mixed return value of called method */ function __invoke($get=array()) { - if(!$this->callHook('preRun', get_class($this), isset($get['action']) ? $get['action'] : 'run', $get)) { - if(isset($get['action']) && $get['action']) { - if(method_exists($this, $get['action'])) { - return $this->{$get['action']}(); + $action = null; + $request = $this->getParam('request'); + if($request) { + if($request->isMethod('get')) + $action = $request->query->get('action'); + elseif($request->isMethod('post')) + $action = $request->request->get('action'); + } + if(!$this->callHook('preRun', get_class($this), $action ? $action : 'run')) { + if($action) { + if(method_exists($this, $action)) { + return $this->{$action}(); } else { - echo "Missing action '".$get['action']."'"; + echo "Missing action '".$action."'"; return false; } } else return $this->run(); } - $this->callHook('postRun', get_class($this), isset($get['action']) ? $get['action'] : 'run', $get); + $this->callHook('postRun', get_class($this), $action ? $action : 'run'); } function setParams($params) {