3 namespace dokuwiki\Extension
;
5 use dokuwiki\Remote\Api
;
6 use ReflectionException
;
10 * Remote Plugin prototype
12 * Add functionality to the remote API in a plugin
14 abstract class RemotePlugin
extends Plugin
22 public function __construct()
24 $this->api
= new Api();
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 array Information about all provided methods. {@see dokuwiki\Remote\RemoteAPI}.
34 * @throws ReflectionException
36 public function _getMethods()
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') {
47 $method_name = $method->name
;
48 if (strpos($method_name, '_') === 0) {
53 $doc = $method->getDocComment();
55 ['/^[ \t]*\/\*+[ \t]*/m', '/[ \t]*\*+[ \t]*/m', '/\*+\/\s*$/m', '/\s*\/\s*$/m'],
62 $data['name'] = $method_name;
67 // get parameter type from doc block type hint
68 foreach ($method->getParameters() as $parameter) {
69 $name = $parameter->name
;
70 $type = 'string'; // we default to string
71 if (preg_match('/^@param[ \t]+([\w|\[\]]+)[ \t]\$' . $name . '/m', $doc, $m)) {
72 $type = $this->cleanTypeHint($m[1]);
74 $data['args'][] = $type;
77 // get return type from doc block type hint
78 if (preg_match('/^@return[ \t]+([\w|\[\]]+)/m', $doc, $m)) {
79 $data['return'] = $this->cleanTypeHint($m[1]);
81 $data['return'] = 'string';
85 $result[$method_name] = $data;
92 * Matches the given type hint against the valid options for the remote API
97 protected function cleanTypeHint($hint)
99 $types = explode('|', $hint);
100 foreach ($types as $t) {
101 if (substr($t, -2) === '[]') {
104 if ($t === 'boolean') {
107 if (in_array($t, ['array', 'string', 'int', 'double', 'bool', 'null', 'date', 'file'])) {
117 protected function getApi()