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