diff options
author | Dominik Eckelmann <deckelmann@gmail.com> | 2012-03-21 13:15:18 +0100 |
---|---|---|
committer | Dominik Eckelmann <deckelmann@gmail.com> | 2012-03-21 13:15:18 +0100 |
commit | 7c35ac36c1dea2d6f26d8184dcbf1fe5afae59ac (patch) | |
tree | 98c845dc14d62ae86df9af3c8c657703f1c9deef /inc/remote.php | |
parent | 96946cc94d3ecb3832e2a1ce35c49743e25329e1 (diff) | |
download | dokuwiki-7c35ac36c1dea2d6f26d8184dcbf1fe5afae59ac.tar.gz dokuwiki-7c35ac36c1dea2d6f26d8184dcbf1fe5afae59ac.zip |
added RPC_CALL_ADD event.
This event enables plugins to register custom method names.
Diffstat (limited to 'inc/remote.php')
-rw-r--r-- | inc/remote.php | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/inc/remote.php b/inc/remote.php index b4cc8e6cc..089a5f7d4 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -35,8 +35,6 @@ class RemoteAccessDeniedException extends RemoteException {} * plugin methods are formed like 'plugin.<plugin name>.<method name>'. * i.e.: plugin.clock.getTime or plugin.clock_gmt.getTime * - * - * * @throws RemoteException */ class RemoteAPI { @@ -52,6 +50,14 @@ class RemoteAPI { */ private $pluginMethods = null; + /** + * @var array contains custom calls to the api. Plugins can use the XML_CALL_REGISTER event. + * The data inside is 'custom.call.something' => array('plugin name', 'remote method name') + * + * The remote method name is the same as in the remote name returned by _getMethods(). + */ + private $pluginCustomCalls = null; + private $dateTransformation; private $fileTransformation; @@ -83,9 +89,34 @@ class RemoteAPI { list($type, $pluginName, $call) = explode('.', $method, 3); if ($type === 'plugin') { return $this->callPlugin($pluginName, $method, $args); - } else { + } + if ($this->coreMethodExist($method)) { return $this->callCoreMethod($method, $args); } + return $this->callCustomCallPlugin($method, $args); + } + + private function coreMethodExist($name) { + $coreMethods = $this->getCoreMethods(); + return array_key_exists($name, $coreMethods); + } + + private function callCustomCallPlugin($method, $args) { + $customCalls = $this->getCustomCallPlugins(); + if (!array_key_exists($method, $customCalls)) { + throw new RemoteException('Method does not exist', -32603); + } + $customCall = $customCalls[$method]; + return $this->callPlugin($customCall[0], $customCall[1], $args); + } + + private function getCustomCallPlugins() { + if ($this->pluginCustomCalls === null) { + $data = array(); + trigger_event('RPC_CALL_ADD', $data); + $this->pluginCustomCalls = $data; + } + return $this->pluginCustomCalls; } private function callPlugin($pluginName, $method, $args) { |