aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/inc/Remote/Api.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/Remote/Api.php')
-rw-r--r--inc/Remote/Api.php51
1 files changed, 25 insertions, 26 deletions
diff --git a/inc/Remote/Api.php b/inc/Remote/Api.php
index 8ff38eadb..99dbf2bd4 100644
--- a/inc/Remote/Api.php
+++ b/inc/Remote/Api.php
@@ -2,6 +2,8 @@
namespace dokuwiki\Remote;
+use dokuwiki\Extension\PluginInterface;
+use dokuwiki\Input\Input;
use dokuwiki\Extension\Event;
use dokuwiki\Extension\RemotePlugin;
@@ -36,17 +38,16 @@ use dokuwiki\Extension\RemotePlugin;
*/
class Api
{
-
/**
- * @var ApiCore
+ * @var ApiCore|\RemoteAPICoreTest
*/
- private $coreMethods = null;
+ private $coreMethods;
/**
* @var array remote methods provided by dokuwiki plugins - will be filled lazy via
* {@see dokuwiki\Remote\RemoteAPI#getPluginMethods}
*/
- private $pluginMethods = null;
+ private $pluginMethods;
/**
* @var array contains custom calls to the api. Plugins can use the XML_CALL_REGISTER event.
@@ -54,7 +55,7 @@ class Api
*
* The remote method name is the same as in the remote name returned by _getMethods().
*/
- private $pluginCustomCalls = null;
+ private $pluginCustomCalls;
private $dateTransformation;
private $fileTransformation;
@@ -64,8 +65,8 @@ class Api
*/
public function __construct()
{
- $this->dateTransformation = array($this, 'dummyTransformation');
- $this->fileTransformation = array($this, 'dummyTransformation');
+ $this->dateTransformation = [$this, 'dummyTransformation'];
+ $this->fileTransformation = [$this, 'dummyTransformation'];
}
/**
@@ -87,13 +88,13 @@ class Api
* @return mixed result of method call, must be a primitive type.
* @throws RemoteException
*/
- public function call($method, $args = array())
+ public function call($method, $args = [])
{
if ($args === null) {
- $args = array();
+ $args = [];
}
// Ensure we have at least one '.' in $method
- list($type, $pluginName, /* $call */) = sexplode('.', $method . '.', 3, '');
+ [$type, $pluginName, /* call */] = sexplode('.', $method . '.', 3, '');
if ($type === 'plugin') {
return $this->callPlugin($pluginName, $method, $args);
}
@@ -129,7 +130,7 @@ class Api
if (!array_key_exists($method, $customCalls)) {
throw new RemoteException('Method does not exist', -32603);
}
- list($plugin, $method) = $customCalls[$method];
+ [$plugin, $method] = $customCalls[$method];
$fullMethod = "plugin.$plugin.$method";
return $this->callPlugin($plugin, $fullMethod, $args);
}
@@ -143,7 +144,7 @@ class Api
private function getCustomCallPlugins()
{
if ($this->pluginCustomCalls === null) {
- $data = array();
+ $data = [];
Event::createAndTrigger('RPC_CALL_ADD', $data);
$this->pluginCustomCalls = $data;
}
@@ -163,14 +164,14 @@ class Api
{
$plugin = plugin_load('remote', $pluginName);
$methods = $this->getPluginMethods();
- if (!$plugin) {
+ if (!$plugin instanceof PluginInterface) {
throw new RemoteException('Method does not exist', -32603);
}
$this->checkAccess($methods[$method]);
$name = $this->getMethodName($methods, $method);
try {
- set_error_handler(array($this, "argumentWarningHandler"), E_WARNING); // for PHP <7.1
- return call_user_func_array(array($plugin, $name), $args);
+ set_error_handler([$this, "argumentWarningHandler"], E_WARNING); // for PHP <7.1
+ return call_user_func_array([$plugin, $name], $args);
} catch (\ArgumentCountError $th) {
throw new RemoteException('Method does not exist - wrong parameter count.', -32603);
} finally {
@@ -195,8 +196,8 @@ class Api
}
$this->checkArgumentLength($coreMethods[$method], $args);
try {
- set_error_handler(array($this, "argumentWarningHandler"), E_WARNING); // for PHP <7.1
- return call_user_func_array(array($this->coreMethods, $this->getMethodName($coreMethods, $method)), $args);
+ set_error_handler([$this, "argumentWarningHandler"], E_WARNING); // for PHP <7.1
+ return call_user_func_array([$this->coreMethods, $this->getMethodName($coreMethods, $method)], $args);
} catch (\ArgumentCountError $th) {
throw new RemoteException('Method does not exist - wrong parameter count.', -32603);
} finally {
@@ -214,10 +215,8 @@ class Api
{
if (!isset($methodMeta['public'])) {
$this->forceAccess();
- } else {
- if ($methodMeta['public'] == '0') {
- $this->forceAccess();
- }
+ } elseif ($methodMeta['public'] == '0') {
+ $this->forceAccess();
}
}
@@ -261,7 +260,7 @@ class Api
{
global $conf;
global $USERINFO;
- /** @var \dokuwiki\Input\Input $INPUT */
+ /** @var Input $INPUT */
global $INPUT;
if (!$conf['remote']) {
@@ -302,7 +301,7 @@ class Api
public function getPluginMethods()
{
if ($this->pluginMethods === null) {
- $this->pluginMethods = array();
+ $this->pluginMethods = [];
$plugins = plugin_list('remote');
foreach ($plugins as $pluginName) {
@@ -310,7 +309,7 @@ class Api
$plugin = plugin_load('remote', $pluginName);
if (!is_subclass_of($plugin, 'dokuwiki\Extension\RemotePlugin')) {
throw new RemoteException(
- "Plugin $pluginName does not implement dokuwiki\Plugin\DokuWiki_Remote_Plugin"
+ "Plugin $pluginName does not implement dokuwiki\Extension\RemotePlugin"
);
}
@@ -331,8 +330,8 @@ class Api
/**
* Collects all the core methods
*
- * @param ApiCore $apiCore this parameter is used for testing. Here you can pass a non-default RemoteAPICore
- * instance. (for mocking)
+ * @param ApiCore|\RemoteAPICoreTest $apiCore this parameter is used for testing.
+ * Here you can pass a non-default RemoteAPICore instance. (for mocking)
* @return array all core methods.
*/
public function getCoreMethods($apiCore = null)