Fix first set of API tests
[dokuwiki.git] / inc / Extension / RemotePlugin.php
blob89525ad409d41bf9e26d430bae6e2624f7c9de03
1 <?php
3 namespace dokuwiki\Extension;
5 use dokuwiki\Remote\Api;
6 use dokuwiki\Remote\ApiCall;
7 use ReflectionException;
8 use ReflectionMethod;
10 /**
11 * Remote Plugin prototype
13 * Add functionality to the remote API in a plugin
15 abstract class RemotePlugin extends Plugin
17 private Api $api;
19 /**
20 * Constructor
22 public function __construct()
24 $this->api = new Api();
27 /**
28 * Get all available methods with remote access.
30 * By default it exports all public methods of a remote plugin. Methods beginning
31 * with an underscore are skipped.
33 * @return ApiCall[] Information about all provided methods. ('methodname' => ApiCall)
34 * @throws ReflectionException
36 public function getMethods()
38 $result = [];
40 $reflection = new \ReflectionClass($this);
41 foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
42 // skip parent methods, only methods further down are exported
43 $declaredin = $method->getDeclaringClass()->name;
44 if ($declaredin === 'dokuwiki\Extension\Plugin' || $declaredin === 'dokuwiki\Extension\RemotePlugin') {
45 continue;
47 $method_name = $method->name;
48 if ($method_name[0] === '_') {
49 continue;
51 if($method_name === 'getMethods') {
52 continue; // skip self, if overridden
55 // add to result
56 $result[$method_name] = new ApiCall([$this, $method_name]);
59 return $result;
62 /**
63 * @deprecated 2023-11-30
65 public function _getMethods()
67 dbg_deprecated('getMethods()');
72 /**
73 * @return Api
75 protected function getApi()
77 return $this->api;