3 namespace dokuwiki\Remote
;
5 use IXR\DataType\Base64
;
7 use IXR\Exception\ServerException
;
11 * Contains needed wrapper functions and registers all available XMLRPC functions.
13 class XmlRpcServer
extends Server
18 * Constructor. Register methods and run Server
20 public function __construct($wait = false)
22 $this->remote
= new Api();
23 $this->remote
->setDateTransformation([$this, 'toDate']);
24 $this->remote
->setFileTransformation([$this, 'toFile']);
25 parent
::__construct(false, false, $wait);
29 public function serve($data = false)
32 if (!$conf['remote']) {
33 throw new ServerException("XML-RPC server not enabled.", -32605);
35 if (!empty($conf['remotecors'])) {
36 header('Access-Control-Allow-Origin: ' . $conf['remotecors']);
39 !isset($_SERVER['CONTENT_TYPE']) ||
41 strtolower($_SERVER['CONTENT_TYPE']) !== 'text/xml' &&
42 strtolower($_SERVER['CONTENT_TYPE']) !== 'application/xml'
45 throw new ServerException('XML-RPC server accepts XML requests only.', -32606);
54 protected function call($methodname, $args)
57 $result = $this->remote
->call($methodname, $args);
59 } catch (AccessDeniedException
$e) {
60 if (!isset($_SERVER['REMOTE_USER'])) {
62 return new ServerException("server error. not authorized to call method $methodname", -32603);
65 return new ServerException("server error. forbidden to call the method $methodname", -32604);
67 } catch (RemoteException
$e) {
68 return new ServerException($e->getMessage(), $e->getCode());
73 * @param string|int $data iso date(yyyy[-]mm[-]dd[ hh:mm[:ss]]) or timestamp
76 public function toDate($data)
78 return new Date($data);
85 public function toFile($data)
87 return new Base64($data);