Failed Conditions
Push — psr2 ( 23f4cc...4cdb68 )
by Andreas
03:34
created

lib/exe/xmlrpc.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
use dokuwiki\Remote\AccessDeniedException;
4
use dokuwiki\Remote\Api;
5
use dokuwiki\Remote\RemoteException;
0 ignored issues
show
This use statement conflicts with another class in this namespace, RemoteException.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
7
if(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__).'/../../');
8
9
require_once(DOKU_INC.'inc/init.php');
10
session_write_close();  //close session
11
12
if(!$conf['remote']) die((new IXR_Error(-32605, "XML-RPC server not enabled."))->getXml());
13
14
/**
15
 * Contains needed wrapper functions and registers all available
16
 * XMLRPC functions.
17
 */
18
class dokuwiki_xmlrpc_server extends IXR_Server {
19
    protected $remote;
20
21
    /**
22
     * Constructor. Register methods and run Server
23
     */
24
    public function __construct(){
25
        $this->remote = new Api();
26
        $this->remote->setDateTransformation(array($this, 'toDate'));
27
        $this->remote->setFileTransformation(array($this, 'toFile'));
28
        parent::__construct();
29
    }
30
31
    /**
32
     * @param string $methodname
33
     * @param array $args
34
     * @return IXR_Error|mixed
35
     */
36
    public function call($methodname, $args){
37
        try {
38
            $result = $this->remote->call($methodname, $args);
39
            return $result;
40
        } catch (AccessDeniedException $e) {
41
            if (!isset($_SERVER['REMOTE_USER'])) {
42
                http_status(401);
43
                return new IXR_Error(-32603, "server error. not authorized to call method $methodname");
44
            } else {
45
                http_status(403);
46
                return new IXR_Error(-32604, "server error. forbidden to call the method $methodname");
47
            }
48
        } catch (RemoteException $e) {
49
            return new IXR_Error($e->getCode(), $e->getMessage());
50
        }
51
    }
52
53
    /**
54
     * @param string|int $data iso date(yyyy[-]mm[-]dd[ hh:mm[:ss]]) or timestamp
55
     * @return IXR_Date
56
     */
57
    public function toDate($data) {
58
        return new IXR_Date($data);
59
    }
60
61
    /**
62
     * @param string $data
63
     * @return IXR_Base64
64
     */
65
    public function toFile($data) {
66
        return new IXR_Base64($data);
67
    }
68
}
69
70
$server = new dokuwiki_xmlrpc_server();
71
72
// vim:ts=4:sw=4:et:
73