tag for release
[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 response payload (you can use the setDebug method to allow analysis of the response)',
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 by the client for received responses when
65     // received charset cannot be determined and mbstring extension is not enabled
66     public static $xmlrpc_defencoding = "UTF-8";
67
68     // The list of encodings used by the server for requests and by the client for responses to detect the charset of
69     // the received payload when
70     // - the charset cannot be determined by looking at http headers, xml declaration or BOM
71     // - mbstring extension is enabled
72     public static $xmlrpc_detectencodings = array();
73
74     // The encoding used internally by PHP.
75     // String values received as xml will be converted to this, and php strings will be converted to xml as if
76     // having been coded with this.
77     // Valid also when defining names of xmlrpc methods
78     public static $xmlrpc_internalencoding = "UTF-8";
79
80     public static $xmlrpcName = "XML-RPC for PHP";
81     public static $xmlrpcVersion = "4.5.1";
82
83     // let user errors start at 800
84     public static $xmlrpcerruser = 800;
85     // let XML parse errors start at 100
86     public static $xmlrpcerrxml = 100;
87
88     // set to TRUE to enable correct decoding of <NIL/> and <EX:NIL/> values
89     public static $xmlrpc_null_extension = false;
90
91     // set to TRUE to enable encoding of php NULL values to <EX:NIL/> instead of <NIL/>
92     public static $xmlrpc_null_apache_encoding = false;
93
94     public static $xmlrpc_null_apache_encoding_ns = "http://ws.apache.org/xmlrpc/namespaces/extensions";
95
96     // number of decimal digits used to serialize Double values
97     public static $xmlpc_double_precision = 128;
98
99     /**
100      * A function to be used for compatibility with legacy code: it creates all global variables which used to be declared,
101      * such as library version etc...
102      */
103     public static function exportGlobals()
104     {
105         $reflection = new \ReflectionClass('PhpXmlRpc\PhpXmlRpc');
106         foreach ($reflection->getStaticProperties() as $name => $value) {
107             $GLOBALS[$name] = $value;
108         }
109
110         // NB: all the variables exported into the global namespace below here do NOT guarantee 100% compatibility,
111         // as they are NOT reimported back during calls to importGlobals()
112
113         $reflection = new \ReflectionClass('PhpXmlRpc\Value');
114         foreach ($reflection->getStaticProperties() as $name => $value) {
115             $GLOBALS[$name] = $value;
116         }
117
118         $parser = new Helper\XMLParser();
119         $reflection = new \ReflectionClass('PhpXmlRpc\Helper\XMLParser');
120         foreach ($reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $name => $value) {
121             if (in_array($value->getName(), array('xmlrpc_valid_parents')))
122             {
123                 $GLOBALS[$value->getName()] = $value->getValue($parser);
124             }
125         }
126
127         $charset = Helper\Charset::instance();
128         $GLOBALS['xml_iso88591_Entities'] = $charset->getEntities('iso88591');
129     }
130
131     /**
132      * A function to be used for compatibility with legacy code: it gets the values of all global variables which used
133      * to be declared, such as library version etc... and sets them to php classes.
134      * It should be used by code which changed the values of those global variables to alter the working of the library.
135      * Example code:
136      * 1. include xmlrpc.inc
137      * 2. set the values, e.g. $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
138      * 3. import them: PhpXmlRpc\PhpXmlRpc::importGlobals();
139      * 4. run your own code.
140      */
141     public static function importGlobals()
142     {
143         $reflection = new \ReflectionClass('PhpXmlRpc\PhpXmlRpc');
144         $staticProperties = $reflection->getStaticProperties();
145         foreach ($staticProperties as $name => $value) {
146             if (isset($GLOBALS[$name])) {
147                 self::$$name = $GLOBALS[$name];
148             }
149         }
150     }
151
152 }