Completed
Push — psr2 ( 272a98...1cdd00 )
by Andreas
19:29 queued 15:19
created

XmlRpcServer::call()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 4
nop 2
dl 0
loc 17
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace dokuwiki\Remote;
4
5
/**
6
 * Contains needed wrapper functions and registers all available XMLRPC functions.
7
 */
8
class XmlRpcServer extends \IXR_Server
9
{
10
    protected $remote;
11
12
    /**
13
     * Constructor. Register methods and run Server
14
     */
15
    public function __construct()
16
    {
17
        $this->remote = new Api();
18
        $this->remote->setDateTransformation(array($this, 'toDate'));
19
        $this->remote->setFileTransformation(array($this, 'toFile'));
20
        parent::__construct();
21
    }
22
23
    /**
24
     * @inheritdoc
25
     */
26
    public function call($methodname, $args)
27
    {
28
        try {
29
            $result = $this->remote->call($methodname, $args);
30
            return $result;
31
        } /** @noinspection PhpRedundantCatchClauseInspection */ catch (AccessDeniedException $e) {
32
            if (!isset($_SERVER['REMOTE_USER'])) {
33
                http_status(401);
34
                return new \IXR_Error(-32603, "server error. not authorized to call method $methodname");
35
            } else {
36
                http_status(403);
37
                return new \IXR_Error(-32604, "server error. forbidden to call the method $methodname");
38
            }
39
        } catch (RemoteException $e) {
40
            return new \IXR_Error($e->getCode(), $e->getMessage());
41
        }
42
    }
43
44
    /**
45
     * @param string|int $data iso date(yyyy[-]mm[-]dd[ hh:mm[:ss]]) or timestamp
46
     * @return \IXR_Date
47
     */
48
    public function toDate($data)
49
    {
50
        return new \IXR_Date($data);
51
    }
52
53
    /**
54
     * @param string $data
55
     * @return \IXR_Base64
56
     */
57
    public function toFile($data)
58
    {
59
        return new \IXR_Base64($data);
60
    }
61
}
62