Completed
Push — master ( 87b7a4...6ce28d )
by Gaetano
11:11 queued 06:38
created

PhpXmlRpc::importGlobals()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
c 0
b 0
f 0
nc 3
nop 0
dl 0
loc 7
rs 10
ccs 6
cts 6
cp 1
crap 3
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.4.0";
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
    /**
97
     * A function to be used for compatibility with legacy code: it creates all global variables which used to be declared,
98
     * such as library version etc...
99
     */
100
    public static function exportGlobals()
101
    {
102
        $reflection = new \ReflectionClass('PhpXmlRpc\PhpXmlRpc');
103
        foreach ($reflection->getStaticProperties() as $name => $value) {
104
            $GLOBALS[$name] = $value;
105
        }
106
107
        // NB: all the variables exported into the global namespace below here do NOT guarantee 100% compatibility,
108
        // as they are NOT reimported back during calls to importGlobals()
109
110
        $reflection = new \ReflectionClass('PhpXmlRpc\Value');
111
        foreach ($reflection->getStaticProperties() as $name => $value) {
112
            $GLOBALS[$name] = $value;
113
        }
114
115
        $parser = new Helper\XMLParser();
116
        $reflection = new \ReflectionClass('PhpXmlRpc\Helper\XMLParser');
117
        foreach ($reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $name => $value) {
118
            if (in_array($value->getName(), array('xmlrpc_valid_parents')))
119
            {
120
                $GLOBALS[$value->getName()] = $value->getValue($parser);
121
            }
122
        }
123
124
        $charset = Helper\Charset::instance();
125
        $GLOBALS['xml_iso88591_Entities'] = $charset->getEntities('iso88591');
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Helper\Charset::getEntities() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

125
        $GLOBALS['xml_iso88591_Entities'] = /** @scrutinizer ignore-deprecated */ $charset->getEntities('iso88591');
Loading history...
126
    }
127
128
    /**
129
     * A function to be used for compatibility with legacy code: it gets the values of all global variables which used
130
     * to be declared, such as library version etc... and sets them to php classes.
131
     * It should be used by code which changed the values of those global variables to alter the working of the library.
132
     * Example code:
133
     * 1. include xmlrpc.inc
134
     * 2. set the values, e.g. $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
135
     * 3. import them: PhpXmlRpc\PhpXmlRpc::importGlobals();
136
     * 4. run your own code.
137
     */
138 2
    public static function importGlobals()
139
    {
140 2
        $reflection = new \ReflectionClass('PhpXmlRpc\PhpXmlRpc');
141 2
        $staticProperties = $reflection->getStaticProperties();
142 2
        foreach ($staticProperties as $name => $value) {
143 2
            if (isset($GLOBALS[$name])) {
144 2
                self::$$name = $GLOBALS[$name];
145
            }
146
        }
147 2
    }
148
149
}
150