Increase backwards compatibility with version 3: make ALL global vars available which...
[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         // NB: all the variables exported into the global namespace below here do NOT guarantee 100%
99         // compatibility, as they are NOT reimported back during calls to importGlobals()
100         
101         $reflection = new \ReflectionClass('PhpXmlRpc\Value');
102         foreach ($reflection->getStaticProperties() as $name => $value) {
103             $GLOBALS[$name] = $value;
104         }
105
106         $parser = new Helper\XMLParser();
107         $reflection = new \ReflectionClass('PhpXmlRpc\Helper\XMLParser');
108         foreach ($reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $name => $value) {
109             if (in_array($value->getName(), array('xmlrpc_valid_parents')))
110             {
111                 $GLOBALS[$value->getName()] = $value->getValue($parser);
112             }
113         }
114
115         $charset = Helper\Charset::instance();
116         $GLOBALS['xml_iso88591_Entities'] = $charset->getEntities('iso88591');
117     }
118
119     /**
120      * A function to be used for compatibility with legacy code: it gets the values of all global variables which used
121      * to be declared, such as library version etc... and sets them to php classes.
122      * It should be used by code which changed the values of those global variables to alter the working of the library.
123      * Example code:
124      * 1. include xmlrpc.inc
125      * 2. set the values, e.g. $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
126      * 3. import them: PhpXmlRpc\PhpXmlRpc::importGlobals();
127      * 4. run your own code.
128      */
129     public static function importGlobals()
130     {
131         $reflection = new \ReflectionClass('PhpXmlRpc\PhpXmlRpc');
132         $staticProperties = $reflection->getStaticProperties();
133         foreach ($staticProperties as $name => $value) {
134             if (isset($GLOBALS[$name])) {
135                 self::$$name = $GLOBALS[$name];
136             }
137         }
138     }
139 }