diff options
author | Andreas Gohr <andi@splitbrain.org> | 2017-03-11 12:50:40 +0100 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2017-03-31 11:56:35 +0200 |
commit | 73522543bc6b95590563b07feeb1b3d0113a2018 (patch) | |
tree | ec4bcc77edeb26f0f336400915d5070ed107f011 /inc/ActionRouter.php | |
parent | e5802cb76bfc6a2db174f805c78e339cc79a226a (diff) | |
download | dokuwiki-73522543bc6b95590563b07feeb1b3d0113a2018.tar.gz dokuwiki-73522543bc6b95590563b07feeb1b3d0113a2018.zip |
fixed export action by supporting underscores in actions
Now underscores can be used to have sub actions. The loader will try to
find an exact match first, then begin removing parts from the end until
a matching action is found.
Diffstat (limited to 'inc/ActionRouter.php')
-rw-r--r-- | inc/ActionRouter.php | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/inc/ActionRouter.php b/inc/ActionRouter.php index 8f87ac993..2e7e9a07c 100644 --- a/inc/ActionRouter.php +++ b/inc/ActionRouter.php @@ -95,8 +95,7 @@ class ActionRouter { $this->transitionAction($presetup, $actionname); } else { // event said the action should be kept, assume action plugin will handle it later - $this->action = new Plugin(); - $this->action->setActionName($actionname); + $this->action = new Plugin($actionname); } $evt->advise_after(); @@ -173,15 +172,29 @@ class ActionRouter { /** * Load the given action * + * This translates the given name to a class name by uppercasing the first letter. + * Underscores translate to camelcase names. For actions with underscores, the different + * parts are removed beginning from the end until a matching class is found. The instatiated + * Action will always have the full original action set as Name + * + * Example: 'export_raw' -> ExportRaw then 'export' -> 'Export' + * * @param $actionname * @return AbstractAction * @throws NoActionException */ protected function loadAction($actionname) { - $class = 'dokuwiki\\Action\\' . ucfirst(strtolower($actionname)); - if(class_exists($class)) { - return new $class; + $actionname = strtolower($actionname); // FIXME is this needed here? should we run a cleanup somewhere else? + $parts = explode('_', $actionname); + while($parts) { + $load = join('_', $parts); + $class = 'dokuwiki\\Action\\' . str_replace('_', '', ucwords($load, '_')); + if(class_exists($class)) { + return new $class($actionname); + } + array_pop($parts); } + throw new NoActionException(); } |