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