File: RemotePlugin.php

package info (click to toggle)
dokuwiki 2024-02-06b%2Bdfsg-9
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 24,624 kB
  • sloc: php: 97,851; javascript: 3,724; sh: 599; makefile: 70; xml: 34
file content (79 lines) | stat: -rw-r--r-- 1,876 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php

namespace dokuwiki\Extension;

use dokuwiki\Remote\Api;
use dokuwiki\Remote\ApiCall;
use ReflectionException;
use ReflectionMethod;

/**
 * Remote Plugin prototype
 *
 * Add functionality to the remote API in a plugin
 */
abstract class RemotePlugin extends Plugin
{
    private Api $api;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->api = new Api();
    }

    /**
     * Get all available methods with remote access.
     *
     * By default it exports all public methods of a remote plugin. Methods beginning
     * with an underscore are skipped.
     *
     * @return ApiCall[] Information about all provided methods. ('methodname' => ApiCall)
     * @throws ReflectionException
     */
    public function getMethods()
    {
        $result = [];

        $reflection = new \ReflectionClass($this);
        foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
            // skip parent methods, only methods further down are exported
            $declaredin = $method->getDeclaringClass()->name;
            if ($declaredin === 'dokuwiki\Extension\Plugin' || $declaredin === 'dokuwiki\Extension\RemotePlugin') {
                continue;
            }
            $method_name = $method->name;
            if ($method_name[0] ===  '_') {
                continue;
            }
            if ($method_name === 'getMethods') {
                continue; // skip self, if overridden
            }

            // add to result
            $result[$method_name] = new ApiCall([$this, $method_name], 'plugins');
        }

        return $result;
    }

    /**
     * @deprecated 2023-11-30
     */
    public function _getMethods()
    {
        dbg_deprecated('getMethods()');
    }



    /**
     * @return Api
     */
    protected function getApi()
    {
        return $this->api;
    }
}