openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 8070604e8ba04ca595a80ca5e034d7c2957be462
parent 692fb2c740f0f369ab90ee269253b5f661779d7e
Author: Jan Dankert <devnull@localhost>
Date:   Sun, 28 Oct 2018 21:28:14 +0100

Neu: Benutzen von ReflectionMethod, um zu ermitteln, ob die Actionmethode vererbt wurde. Dadurch kann das richtige Template gezogen werden, ohne dass die ActionMethode den ActionName selber verbiegen muss.

Diffstat:
modules/cms-core/Dispatcher.class.php | 20++++++++++++++------
modules/cms-core/action/ObjectAction.class.php | 7-------
2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/modules/cms-core/Dispatcher.class.php b/modules/cms-core/Dispatcher.class.php @@ -19,6 +19,7 @@ use ObjectNotFoundException; use OpenRatException; use SecurityException; use Session; +use Spyc; /** @@ -55,12 +56,13 @@ class Dispatcher $this->setContentLanguageHeader(); - - // Nachdem die Konfiguration gelesen wurde, kann nun der Logger benutzt werden. require_once(OR_MODULES_DIR . "logger/require." . PHP_EXT); $this->initializeLogger(); + // Sollte nur 1x pro Sitzung ausgeführt werden. Wie ermitteln wir das? + //if ( DEVELOPMENT ) + // Logger::debug( "Effective configuration:\n".Spyc::YAMLDump($conf) ); if (!empty($conf['security']['umask'])) umask(octdec($conf['security']['umask'])); @@ -213,7 +215,6 @@ class Dispatcher $customConfig = $configLoader->load(); $conf = array_replace_recursive($conf, $customConfig); - $conf['build'] = parse_ini_file('build.ini'); $conf['version'] = parse_ini_file('version.ini'); // Sprache lesen @@ -305,19 +306,26 @@ class Dispatcher Logger::debug("Dispatcher executing {$this->request->action}/{$this->request->method}/" . @$REQ[REQ_PARAM_ID].' -> '.$actionClassName.'#'.$subactionMethodName.'() embed='.$this->request->isEmbedded); - if (!method_exists($do, $subactionMethodName)) - throw new BadMethodCallException("Method '$subactionMethodName' does not exist"); try { - $do->$subactionMethodName(); // <== Executing the Action + $method = new \ReflectionMethod($do,$subactionMethodName); + $declaredClassName = $method->getDeclaringClass()->getShortName(); + $declaredActionName = strtolower(substr($declaredClassName,0,strpos($declaredClassName,'Action'))); + + $method->invoke($do); // <== Executing the Action } catch (\ValidationException $ve) { $do->addValidationError( $ve->fieldName ); } + catch (\ReflectionException $re) + { + throw new BadMethodCallException("Method '$subactionMethodName' does not exist",0,$re); + } // The action is able to change its method name. $this->request = $do->request; + $this->request->action = $declaredActionName; $result = $do->getOutputData(); diff --git a/modules/cms-core/action/ObjectAction.class.php b/modules/cms-core/action/ObjectAction.class.php @@ -354,8 +354,6 @@ class ObjectAction extends Action $this->setTemplateVar('acls',$acllist ); $this->setTemplateVars( $o->getAssocRelatedAclTypes() ); - - $this->request->action = 'object'; } @@ -371,8 +369,6 @@ class ObjectAction extends Action $acllist = array(); $this->setTemplateVar('acls',$acllist ); - - $this->request->action = 'object'; } @@ -464,8 +460,6 @@ class ObjectAction extends Action $this->setTemplateVar('languages',$languages ); $this->setTemplateVar('objectid' ,$o->objectid ); $this->setTemplateVar('action' ,$this->request->action); - - $this->request->action = 'object'; } @@ -522,7 +516,6 @@ class ObjectAction extends Action public function settingsView() { $this->setTemplateVar('settings',$this->baseObject->settings); - $this->request->action = 'object'; } public function settingsPost()