Reformat source code: the library
[plcapi.git] / src / PhpXmlRpc.php
1 <?php
2
3 namespace PhpXmlRpc;
4
5 class PhpXmlRpc
6 {
7     static public $xmlrpcerr = array(
8         'unknown_method' => 1,
9         'invalid_return' => 2,
10         'incorrect_params' => 3,
11         'introspect_unknown' => 4,
12         'http_error' => 5,
13         'no_data' => 6,
14         'no_ssl' => 7,
15         'curl_fail' => 8,
16         'invalid_request' => 15,
17         'no_curl' => 16,
18         'server_error' => 17,
19         'multicall_error' => 18,
20         'multicall_notstruct' => 9,
21         'multicall_nomethod' => 10,
22         'multicall_notstring' => 11,
23         'multicall_recursion' => 12,
24         'multicall_noparams' => 13,
25         'multicall_notarray' => 14,
26
27         'cannot_decompress' => 103,
28         'decompress_fail' => 104,
29         'dechunk_fail' => 105,
30         'server_cannot_decompress' => 106,
31         'server_decompress_fail' => 107,
32     );
33
34     static public $xmlrpcstr = array(
35         'unknown_method' => 'Unknown method',
36         'invalid_return' => 'Invalid return payload: enable debugging to examine incoming payload',
37         'incorrect_params' => 'Incorrect parameters passed to method',
38         'introspect_unknown' => "Can't introspect: method unknown",
39         'http_error' => "Didn't receive 200 OK from remote server.",
40         'no_data' => 'No data received from server.',
41         'no_ssl' => 'No SSL support compiled in.',
42         'curl_fail' => 'CURL error',
43         'invalid_request' => 'Invalid request payload',
44         'no_curl' => 'No CURL support compiled in.',
45         'server_error' => 'Internal server error',
46         'multicall_error' => 'Received from server invalid multicall response',
47         'multicall_notstruct' => 'system.multicall expected struct',
48         'multicall_nomethod' => 'missing methodName',
49         'multicall_notstring' => 'methodName is not a string',
50         'multicall_recursion' => 'recursive system.multicall forbidden',
51         'multicall_noparams' => 'missing params',
52         'multicall_notarray' => 'params is not an array',
53
54         'cannot_decompress' => 'Received from server compressed HTTP and cannot decompress',
55         'decompress_fail' => 'Received from server invalid compressed HTTP',
56         'dechunk_fail' => 'Received from server invalid chunked HTTP',
57         'server_cannot_decompress' => 'Received from client compressed HTTP request and cannot decompress',
58         'server_decompress_fail' => 'Received from client invalid compressed HTTP request',
59     );
60
61     // The charset encoding used by the server for received requests and
62     // by the client for received responses when received charset cannot be determined
63     // or is not supported
64     public static $xmlrpc_defencoding = "UTF-8";
65
66     // The encoding used internally by PHP.
67     // String values received as xml will be converted to this, and php strings will be converted to xml
68     // as if having been coded with this
69     public static $xmlrpc_internalencoding = "ISO-8859-1"; // TODO: maybe this would be better as UTF-8, or atleast configurable?
70
71     public static $xmlrpcName = "XML-RPC for PHP";
72     public static $xmlrpcVersion = "4.0.0.beta";
73
74     // let user errors start at 800
75     public static $xmlrpcerruser = 800;
76     // let XML parse errors start at 100
77     public static $xmlrpcerrxml = 100;
78
79     // set to TRUE to enable correct decoding of <NIL/> and <EX:NIL/> values
80     public static $xmlrpc_null_extension = false;
81
82     // set to TRUE to enable encoding of php NULL values to <EX:NIL/> instead of <NIL/>
83     public static $xmlrpc_null_apache_encoding = false;
84
85     public static $xmlrpc_null_apache_encoding_ns = "http://ws.apache.org/xmlrpc/namespaces/extensions";
86
87     /**
88      * A function to be used for compatibility with legacy code: it creates all global variables which used to be declared,
89      * such as library version etc...
90      */
91     public static function exportGlobals()
92     {
93         $reflection = new \ReflectionClass('PhpXmlRpc\PhpXmlRpc');
94         foreach ($reflection->getStaticProperties() as $name => $value) {
95             $GLOBALS[$name] = $value;
96         }
97
98         $reflection = new \ReflectionClass('PhpXmlRpc\Value');
99         foreach ($reflection->getStaticProperties() as $name => $value) {
100             $GLOBALS[$name] = $value;
101         }
102     }
103
104     /**
105      * A function to be used for compatibility with legacy code: it gets the values of all global variables which used
106      * to be declared, such as library version etc... and sets them to php classes.
107      * It should be used by code which changed the values of those global variables to alter the working of the library.
108      * Example code:
109      * 1. include xmlrpc.inc
110      * 2. set the values, e.g. $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
111      * 3. import them: PhpXmlRpc\PhpXmlRpc::importGlobals();
112      * 4. run your own code.
113      */
114     public static function importGlobals()
115     {
116         $reflection = new \ReflectionClass('PhpXmlRpc\PhpXmlRpc');
117         $staticProperties = $reflection->getStaticProperties();
118         foreach ($staticProperties as $name => $value) {
119             if (isset($GLOBALS[$name])) {
120                 self::$$name = $GLOBALS[$name];
121             }
122         }
123     }
124 }