Fix: lib version number had not been bumped up
[plcapi.git] / src / PhpXmlRpc.php
1 <?php
2
3 namespace PhpXmlRpc;
4
5 /**
6  * Manages global configuration for operation of the library.
7  */
8 class PhpXmlRpc
9 {
10     static public $xmlrpcerr = array(
11         'unknown_method' => 1,
12         'invalid_return' => 2,
13         'incorrect_params' => 3,
14         'introspect_unknown' => 4,
15         'http_error' => 5,
16         'no_data' => 6,
17         'no_ssl' => 7,
18         'curl_fail' => 8,
19         'invalid_request' => 15,
20         'no_curl' => 16,
21         'server_error' => 17,
22         'multicall_error' => 18,
23         'multicall_notstruct' => 9,
24         'multicall_nomethod' => 10,
25         'multicall_notstring' => 11,
26         'multicall_recursion' => 12,
27         'multicall_noparams' => 13,
28         'multicall_notarray' => 14,
29
30         'cannot_decompress' => 103,
31         'decompress_fail' => 104,
32         'dechunk_fail' => 105,
33         'server_cannot_decompress' => 106,
34         'server_decompress_fail' => 107,
35     );
36
37     static public $xmlrpcstr = array(
38         'unknown_method' => 'Unknown method',
39         'invalid_return' => 'Invalid return payload: enable debugging to examine incoming payload',
40         'incorrect_params' => 'Incorrect parameters passed to method',
41         'introspect_unknown' => "Can't introspect: method unknown",
42         'http_error' => "Didn't receive 200 OK from remote server.",
43         'no_data' => 'No data received from server.',
44         'no_ssl' => 'No SSL support compiled in.',
45         'curl_fail' => 'CURL error',
46         'invalid_request' => 'Invalid request payload',
47         'no_curl' => 'No CURL support compiled in.',
48         'server_error' => 'Internal server error',
49         'multicall_error' => 'Received from server invalid multicall response',
50         'multicall_notstruct' => 'system.multicall expected struct',
51         'multicall_nomethod' => 'missing methodName',
52         'multicall_notstring' => 'methodName is not a string',
53         'multicall_recursion' => 'recursive system.multicall forbidden',
54         'multicall_noparams' => 'missing params',
55         'multicall_notarray' => 'params is not an array',
56
57         'cannot_decompress' => 'Received from server compressed HTTP and cannot decompress',
58         'decompress_fail' => 'Received from server invalid compressed HTTP',
59         'dechunk_fail' => 'Received from server invalid chunked HTTP',
60         'server_cannot_decompress' => 'Received from client compressed HTTP request and cannot decompress',
61         'server_decompress_fail' => 'Received from client invalid compressed HTTP request',
62     );
63
64     // The charset encoding used by the server for received requests and
65     // by the client for received responses when received charset cannot be determined
66     // and mbstring extension is not enabled
67     public static $xmlrpc_defencoding = "UTF-8";
68
69     // The list of encodings used by the server for requests and by the client for responses
70     // to detect the charset of the received payload when
71     // - the charset cannot be determined by looking at http headers, xml declaration or BOM
72     // - mbstring extension is enabled
73     public static $xmlrpc_detectencodings = array();
74
75     // The encoding used internally by PHP.
76     // String values received as xml will be converted to this, and php strings will be converted to xml
77     // as if having been coded with this.
78     // Valid also when defining names of xmlrpc methods
79     public static $xmlrpc_internalencoding = "UTF-8";
80
81     public static $xmlrpcName = "XML-RPC for PHP";
82     public static $xmlrpcVersion = "4.1.0";
83
84     // let user errors start at 800
85     public static $xmlrpcerruser = 800;
86     // let XML parse errors start at 100
87     public static $xmlrpcerrxml = 100;
88
89     // set to TRUE to enable correct decoding of <NIL/> and <EX:NIL/> values
90     public static $xmlrpc_null_extension = false;
91
92     // set to TRUE to enable encoding of php NULL values to <EX:NIL/> instead of <NIL/>
93     public static $xmlrpc_null_apache_encoding = false;
94
95     public static $xmlrpc_null_apache_encoding_ns = "http://ws.apache.org/xmlrpc/namespaces/extensions";
96
97     /**
98      * A function to be used for compatibility with legacy code: it creates all global variables which used to be declared,
99      * such as library version etc...
100      */
101     public static function exportGlobals()
102     {
103         $reflection = new \ReflectionClass('PhpXmlRpc\PhpXmlRpc');
104         foreach ($reflection->getStaticProperties() as $name => $value) {
105             $GLOBALS[$name] = $value;
106         }
107
108         // NB: all the variables exported into the global namespace below here do NOT guarantee 100%
109         // compatibility, as they are NOT reimported back during calls to importGlobals()
110
111         $reflection = new \ReflectionClass('PhpXmlRpc\Value');
112         foreach ($reflection->getStaticProperties() as $name => $value) {
113             $GLOBALS[$name] = $value;
114         }
115
116         $parser = new Helper\XMLParser();
117         $reflection = new \ReflectionClass('PhpXmlRpc\Helper\XMLParser');
118         foreach ($reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $name => $value) {
119             if (in_array($value->getName(), array('xmlrpc_valid_parents')))
120             {
121                 $GLOBALS[$value->getName()] = $value->getValue($parser);
122             }
123         }
124
125         $charset = Helper\Charset::instance();
126         $GLOBALS['xml_iso88591_Entities'] = $charset->getEntities('iso88591');
127     }
128
129     /**
130      * A function to be used for compatibility with legacy code: it gets the values of all global variables which used
131      * to be declared, such as library version etc... and sets them to php classes.
132      * It should be used by code which changed the values of those global variables to alter the working of the library.
133      * Example code:
134      * 1. include xmlrpc.inc
135      * 2. set the values, e.g. $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
136      * 3. import them: PhpXmlRpc\PhpXmlRpc::importGlobals();
137      * 4. run your own code.
138      */
139     public static function importGlobals()
140     {
141         $reflection = new \ReflectionClass('PhpXmlRpc\PhpXmlRpc');
142         $staticProperties = $reflection->getStaticProperties();
143         foreach ($staticProperties as $name => $value) {
144             if (isset($GLOBALS[$name])) {
145                 self::$$name = $GLOBALS[$name];
146             }
147         }
148     }
149
150 }