Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Client often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Client, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
10 | class Client |
||
11 | { |
||
12 | /// @todo: do these need to be public? |
||
13 | public $method = 'http'; |
||
14 | public $server; |
||
15 | public $port = 0; |
||
16 | public $path; |
||
17 | |||
18 | public $errno; |
||
19 | public $errstr; |
||
20 | public $debug = 0; |
||
21 | |||
22 | public $username = ''; |
||
23 | public $password = ''; |
||
24 | public $authtype = 1; |
||
25 | |||
26 | public $cert = ''; |
||
27 | public $certpass = ''; |
||
28 | public $cacert = ''; |
||
29 | public $cacertdir = ''; |
||
30 | public $key = ''; |
||
31 | public $keypass = ''; |
||
32 | public $verifypeer = true; |
||
33 | public $verifyhost = 2; |
||
34 | public $sslversion = 0; // corresponds to CURL_SSLVERSION_DEFAULT |
||
35 | |||
36 | public $proxy = ''; |
||
37 | public $proxyport = 0; |
||
38 | public $proxy_user = ''; |
||
39 | public $proxy_pass = ''; |
||
40 | public $proxy_authtype = 1; |
||
41 | |||
42 | public $cookies = array(); |
||
43 | public $extracurlopts = array(); |
||
44 | |||
45 | /** |
||
46 | * @var bool |
||
47 | * |
||
48 | * This determines whether the multicall() method will try to take advantage of the system.multicall xmlrpc method |
||
49 | * to dispatch to the server an array of requests in a single http roundtrip or simply execute many consecutive http |
||
50 | * calls. Defaults to FALSE, but it will be enabled automatically on the first failure of execution of |
||
51 | * system.multicall. |
||
52 | */ |
||
53 | public $no_multicall = false; |
||
54 | |||
55 | /** |
||
56 | * List of http compression methods accepted by the client for responses. |
||
57 | * NB: PHP supports deflate, gzip compressions out of the box if compiled w. zlib. |
||
58 | * |
||
59 | * NNB: you can set it to any non-empty array for HTTP11 and HTTPS, since |
||
60 | * in those cases it will be up to CURL to decide the compression methods |
||
61 | * it supports. You might check for the presence of 'zlib' in the output of |
||
62 | * curl_version() to determine wheter compression is supported or not |
||
63 | */ |
||
64 | public $accepted_compression = array(); |
||
65 | |||
66 | /** |
||
67 | * Name of compression scheme to be used for sending requests. |
||
68 | * Either null, gzip or deflate. |
||
69 | */ |
||
70 | |||
71 | public $request_compression = ''; |
||
72 | /** |
||
73 | * CURL handle: used for keep-alive connections (PHP 4.3.8 up, see: |
||
74 | * http://curl.haxx.se/docs/faq.html#7.3). |
||
75 | */ |
||
76 | public $xmlrpc_curl_handle = null; |
||
77 | |||
78 | /// Whether to use persistent connections for http 1.1 and https |
||
79 | public $keepalive = false; |
||
80 | |||
81 | /// Charset encodings that can be decoded without problems by the client |
||
82 | public $accepted_charset_encodings = array(); |
||
83 | |||
84 | /** |
||
85 | * The charset encoding that will be used for serializing request sent by the client. |
||
86 | * It defaults to NULL, which means using US-ASCII and encoding all characters outside of the ASCII range using |
||
87 | * their xml character entity representation (this has the benefit that line end characters will not be mangled in |
||
88 | * the transfer, a CR-LF will be preserved as well as a singe LF). |
||
89 | * Valid values are 'US-ASCII', 'UTF-8' and 'ISO-8859-1' |
||
90 | */ |
||
91 | public $request_charset_encoding = ''; |
||
92 | |||
93 | /** |
||
94 | * Decides the content of Response objects returned by calls to send() and multicall(). |
||
95 | * Valid values are 'xmlrpcvals', 'phpvals' or 'xml'. |
||
96 | * |
||
97 | * Determines whether the value returned inside an Response object as results of calls to the send() and multicall() |
||
98 | * methods will be a Value object, a plain php value or a raw xml string. |
||
99 | * Allowed values are 'xmlrpcvals' (the default), 'phpvals' and 'xml'. |
||
100 | * To allow the user to differentiate between a correct and a faulty response, fault responses will be returned as |
||
101 | * Response objects in any case. |
||
102 | * Note that the 'phpvals' setting will yield faster execution times, but some of the information from the original |
||
103 | * response will be lost. It will be e.g. impossible to tell whether a particular php string value was sent by the |
||
104 | * server as an xmlrpc string or base64 value. |
||
105 | */ |
||
106 | public $return_type = 'xmlrpcvals'; |
||
107 | |||
108 | /** |
||
109 | * Sent to servers in http headers. |
||
110 | */ |
||
111 | public $user_agent; |
||
112 | |||
113 | /** |
||
114 | * @param string $path either the PATH part of the xmlrpc server URL, or complete server URL (in which case you |
||
115 | * should use and empty string for all other parameters) |
||
116 | * e.g. /xmlrpc/server.php |
||
117 | * e.g. http://phpxmlrpc.sourceforge.net/server.php |
||
118 | * e.g. https://james:[email protected]:443/xmlrpcserver?agent=007 |
||
119 | * @param string $server the server name / ip address |
||
120 | * @param integer $port the port the server is listening on, when omitted defaults to 80 or 443 depending on |
||
121 | * protocol used |
||
122 | * @param string $method the http protocol variant: defaults to 'http'; 'https' and 'http11' can be used if CURL is |
||
123 | * installed. The value set here can be overridden in any call to $this->send(). |
||
124 | */ |
||
125 | public function __construct($path, $server = '', $port = '', $method = '') |
||
126 | { |
||
127 | // allow user to specify all params in $path |
||
128 | if ($server == '' and $port == '' and $method == '') { |
||
|
|||
129 | $parts = parse_url($path); |
||
130 | $server = $parts['host']; |
||
131 | $path = isset($parts['path']) ? $parts['path'] : ''; |
||
132 | if (isset($parts['query'])) { |
||
133 | $path .= '?' . $parts['query']; |
||
134 | } |
||
135 | if (isset($parts['fragment'])) { |
||
136 | $path .= '#' . $parts['fragment']; |
||
137 | } |
||
138 | if (isset($parts['port'])) { |
||
139 | $port = $parts['port']; |
||
140 | } |
||
141 | if (isset($parts['scheme'])) { |
||
142 | $method = $parts['scheme']; |
||
143 | } |
||
144 | if (isset($parts['user'])) { |
||
145 | $this->username = $parts['user']; |
||
146 | } |
||
147 | if (isset($parts['pass'])) { |
||
148 | $this->password = $parts['pass']; |
||
149 | } |
||
150 | } |
||
151 | if ($path == '' || $path[0] != '/') { |
||
152 | $this->path = '/' . $path; |
||
153 | } else { |
||
154 | $this->path = $path; |
||
155 | } |
||
156 | $this->server = $server; |
||
157 | if ($port != '') { |
||
158 | $this->port = $port; |
||
159 | } |
||
160 | if ($method != '') { |
||
161 | $this->method = $method; |
||
162 | } |
||
163 | |||
164 | // if ZLIB is enabled, let the client by default accept compressed responses |
||
165 | if (function_exists('gzinflate') || ( |
||
166 | function_exists('curl_init') && (($info = curl_version()) && |
||
167 | ((is_string($info) && strpos($info, 'zlib') !== null) || isset($info['libz_version']))) |
||
168 | ) |
||
169 | ) { |
||
170 | $this->accepted_compression = array('gzip', 'deflate'); |
||
171 | } |
||
172 | |||
173 | // keepalives: enabled by default |
||
174 | $this->keepalive = true; |
||
175 | |||
176 | // by default the xml parser can support these 3 charset encodings |
||
177 | $this->accepted_charset_encodings = array('UTF-8', 'ISO-8859-1', 'US-ASCII'); |
||
178 | |||
179 | // Add all charsets which mbstring can handle, but remove junk not found in IANA registry at |
||
180 | // in http://www.iana.org/assignments/character-sets/character-sets.xhtml |
||
181 | // NB: this is disabled to avoid making all the requests sent huge... mbstring supports more than 80 charsets! |
||
182 | /*if (function_exists('mb_list_encodings')) { |
||
183 | |||
184 | $encodings = array_diff(mb_list_encodings(), array('pass', 'auto', 'wchar', 'BASE64', 'UUENCODE', 'ASCII', |
||
185 | 'HTML-ENTITIES', 'Quoted-Printable', '7bit','8bit', 'byte2be', 'byte2le', 'byte4be', 'byte4le')); |
||
186 | $this->accepted_charset_encodings = array_unique(array_merge($this->accepted_charset_encodings, $encodings)); |
||
187 | }*/ |
||
188 | |||
189 | // initialize user_agent string |
||
190 | $this->user_agent = PhpXmlRpc::$xmlrpcName . ' ' . PhpXmlRpc::$xmlrpcVersion; |
||
191 | } |
||
192 | |||
193 | /** |
||
194 | * Enable/disable the echoing to screen of the xmlrpc responses received. The default is not no output anything. |
||
195 | * |
||
196 | * The debugging information at level 1 includes the raw data returned from the XML-RPC server it was querying |
||
197 | * (including bot HTTP headers and the full XML payload), and the PHP value the client attempts to create to |
||
198 | * represent the value returned by the server |
||
199 | * At level2, the complete payload of the xmlrpc request is also printed, before being sent t the server. |
||
200 | * |
||
201 | * This option can be very useful when debugging servers as it allows you to see exactly what the client sends and |
||
202 | * the server returns. |
||
203 | * |
||
204 | * @param integer $in values 0, 1 and 2 are supported (2 = echo sent msg too, before received response) |
||
205 | */ |
||
206 | public function setDebug($level) |
||
207 | { |
||
208 | $this->debug = $level; |
||
209 | } |
||
210 | |||
211 | /** |
||
212 | * Sets the username and password for authorizing the client to the server. |
||
213 | * |
||
214 | * With the default (HTTP) transport, this information is used for HTTP Basic authorization. |
||
215 | * Note that username and password can also be set using the class constructor. |
||
216 | * With HTTP 1.1 and HTTPS transport, NTLM and Digest authentication protocols are also supported. To enable them use |
||
217 | * the constants CURLAUTH_DIGEST and CURLAUTH_NTLM as values for the auth type parameter. |
||
218 | * |
||
219 | * @param string $user username |
||
220 | * @param string $password password |
||
221 | * @param integer $authType auth type. See curl_setopt man page for supported auth types. Defaults to CURLAUTH_BASIC |
||
222 | * (basic auth). Note that auth types NTLM and Digest will only work if the Curl php |
||
223 | * extension is enabled. |
||
224 | */ |
||
225 | public function setCredentials($user, $password, $authType = 1) |
||
226 | { |
||
227 | $this->username = $user; |
||
228 | $this->password = $password; |
||
229 | $this->authtype = $authType; |
||
230 | } |
||
231 | |||
232 | /** |
||
233 | * Set the optional certificate and passphrase used in SSL-enabled communication with a remote server. |
||
234 | * |
||
235 | * Note: to retrieve information about the client certificate on the server side, you will need to look into the |
||
236 | * environment variables which are set up by the webserver. Different webservers will typically set up different |
||
237 | * variables. |
||
238 | * |
||
239 | * @param string $cert the name of a file containing a PEM formatted certificate |
||
240 | * @param string $certPass the password required to use it |
||
241 | */ |
||
242 | public function setCertificate($cert, $certPass = '') |
||
243 | { |
||
244 | $this->cert = $cert; |
||
245 | $this->certpass = $certPass; |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * Add a CA certificate to verify server with in SSL-enabled communication when SetSSLVerifypeer has been set to TRUE. |
||
250 | * |
||
251 | * See the php manual page about CURLOPT_CAINFO for more details. |
||
252 | * |
||
253 | * @param string $caCert certificate file name (or dir holding certificates) |
||
254 | * @param bool $isDir set to true to indicate cacert is a dir. defaults to false |
||
255 | */ |
||
256 | public function setCaCertificate($caCert, $isDir = false) |
||
257 | { |
||
258 | if ($isDir) { |
||
259 | $this->cacertdir = $caCert; |
||
260 | } else { |
||
261 | $this->cacert = $caCert; |
||
262 | } |
||
263 | } |
||
264 | |||
265 | /** |
||
266 | * Set attributes for SSL communication: private SSL key. |
||
267 | * |
||
268 | * NB: does not work in older php/curl installs. |
||
269 | * Thanks to Daniel Convissor. |
||
270 | * |
||
271 | * @param string $key The name of a file containing a private SSL key |
||
272 | * @param string $keyPass The secret password needed to use the private SSL key |
||
273 | */ |
||
274 | public function setKey($key, $keyPass) |
||
275 | { |
||
276 | $this->key = $key; |
||
277 | $this->keypass = $keyPass; |
||
278 | } |
||
279 | |||
280 | /** |
||
281 | * Set attributes for SSL communication: verify the remote host's SSL certificate, and cause the connection to fail |
||
282 | * if the cert verification fails. |
||
283 | * |
||
284 | * By default, verification is enabled. |
||
285 | * To specify custom SSL certificates to validate the server with, use the setCaCertificate method. |
||
286 | * |
||
287 | * @param bool $i enable/disable verification of peer certificate |
||
288 | */ |
||
289 | public function setSSLVerifyPeer($i) |
||
290 | { |
||
291 | $this->verifypeer = $i; |
||
292 | } |
||
293 | |||
294 | /** |
||
295 | * Set attributes for SSL communication: verify the remote host's SSL certificate's common name (CN). |
||
296 | * |
||
297 | * Note that support for value 1 has been removed in cURL 7.28.1 |
||
298 | * |
||
299 | * @param int $i Set to 1 to only the existence of a CN, not that it matches |
||
300 | */ |
||
301 | public function setSSLVerifyHost($i) |
||
302 | { |
||
303 | $this->verifyhost = $i; |
||
304 | } |
||
305 | |||
306 | /** |
||
307 | * Set attributes for SSL communication: SSL version to use. Best left at 0 (default value ): let cURL decide |
||
308 | * |
||
309 | * @param int $i |
||
310 | */ |
||
311 | public function setSSLVersion($i) |
||
312 | { |
||
313 | $this->sslversion = $i; |
||
314 | } |
||
315 | |||
316 | /** |
||
317 | * Set proxy info. |
||
318 | * |
||
319 | * NB: CURL versions before 7.11.10 cannot use a proxy to communicate with https servers. |
||
320 | * |
||
321 | * @param string $proxyHost |
||
322 | * @param string $proxyPort Defaults to 8080 for HTTP and 443 for HTTPS |
||
323 | * @param string $proxyUsername Leave blank if proxy has public access |
||
324 | * @param string $proxyPassword Leave blank if proxy has public access |
||
325 | * @param int $proxyAuthType defaults to CURLAUTH_BASIC (Basic authentication protocol); set to constant CURLAUTH_NTLM |
||
326 | * to use NTLM auth with proxy (has effect only when the client uses the HTTP 1.1 protocol) |
||
327 | */ |
||
328 | public function setProxy($proxyHost, $proxyPort, $proxyUsername = '', $proxyPassword = '', $proxyAuthType = 1) |
||
329 | { |
||
330 | $this->proxy = $proxyHost; |
||
331 | $this->proxyport = $proxyPort; |
||
332 | $this->proxy_user = $proxyUsername; |
||
333 | $this->proxy_pass = $proxyPassword; |
||
334 | $this->proxy_authtype = $proxyAuthType; |
||
335 | } |
||
336 | |||
337 | /** |
||
338 | * Enables/disables reception of compressed xmlrpc responses. |
||
339 | * |
||
340 | * This requires the "zlib" extension to be enabled in your php install. If it is, by default xmlrpc_client |
||
341 | * instances will enable reception of compressed content. |
||
342 | * Note that enabling reception of compressed responses merely adds some standard http headers to xmlrpc requests. |
||
343 | * It is up to the xmlrpc server to return compressed responses when receiving such requests. |
||
344 | * |
||
345 | * @param string $compMethod either 'gzip', 'deflate', 'any' or '' |
||
346 | */ |
||
347 | public function setAcceptedCompression($compMethod) |
||
348 | { |
||
349 | if ($compMethod == 'any') { |
||
350 | $this->accepted_compression = array('gzip', 'deflate'); |
||
351 | } elseif ($compMethod == false) { |
||
352 | $this->accepted_compression = array(); |
||
353 | } else { |
||
354 | $this->accepted_compression = array($compMethod); |
||
355 | } |
||
356 | } |
||
357 | |||
358 | /** |
||
359 | * Enables/disables http compression of xmlrpc request. |
||
360 | * |
||
361 | * This requires the "zlib" extension to be enabled in your php install. |
||
362 | * Take care when sending compressed requests: servers might not support them (and automatic fallback to |
||
363 | * uncompressed requests is not yet implemented). |
||
364 | * |
||
365 | * @param string $compMethod either 'gzip', 'deflate' or '' |
||
366 | */ |
||
367 | public function setRequestCompression($compMethod) |
||
368 | { |
||
369 | $this->request_compression = $compMethod; |
||
370 | } |
||
371 | |||
372 | /** |
||
373 | * Adds a cookie to list of cookies that will be sent to server with every further request (useful e.g. for keeping |
||
374 | * session info outside of the xml-rpc payload). |
||
375 | * |
||
376 | * NB: By default cookies are sent using the 'original/netscape' format, which is also the same as the RFC 2965; |
||
377 | * setting any param but name and value will turn the cookie into a 'version 1' cookie (i.e. RFC 2109 cookie) that |
||
378 | * might not be fully supported by the server. Note that RFC 2109 has currently 'historic' status... |
||
379 | * |
||
380 | * @param string $name nb: will not be escaped in the request's http headers. Take care not to use CTL chars or |
||
381 | * separators! |
||
382 | * @param string $value |
||
383 | * @param string $path leave this empty unless the xml-rpc server only accepts RFC 2109 cookies |
||
384 | * @param string $domain leave this empty unless the xml-rpc server only accepts RFC 2109 cookies |
||
385 | * @param int $port leave this empty unless the xml-rpc server only accepts RFC 2109 cookies |
||
386 | * |
||
387 | * @todo check correctness of urlencoding cookie value (copied from php way of doing it, but php is generally sending |
||
388 | * response not requests. We do the opposite...) |
||
389 | * @todo strip invalid chars from cookie name? As per RFC6265, we should follow RFC2616, Section 2.2 |
||
390 | */ |
||
391 | public function setCookie($name, $value = '', $path = '', $domain = '', $port = null) |
||
403 | |||
404 | /** |
||
405 | * Directly set cURL options, for extra flexibility (when in cURL mode). |
||
406 | * |
||
407 | * It allows eg. to bind client to a specific IP interface / address. |
||
408 | * |
||
409 | * @param array $options |
||
410 | */ |
||
411 | public function setCurlOptions($options) |
||
412 | { |
||
413 | $this->extracurlopts = $options; |
||
414 | } |
||
415 | |||
416 | /** |
||
417 | * Set user-agent string that will be used by this client instance in http headers sent to the server. |
||
418 | * |
||
419 | * The default user agent string includes the name of this library and the version number. |
||
420 | * |
||
421 | * @param string $agentString |
||
422 | */ |
||
423 | public function setUserAgent($agentString) |
||
427 | |||
428 | /** |
||
429 | * Send an xmlrpc request to the server. |
||
430 | * |
||
431 | * @param Request|Request[]|string $req The Request object, or an array of requests for using multicall, or the |
||
432 | * complete xml representation of a request. |
||
433 | * When sending an array of Request objects, the client will try to make use of |
||
434 | * a single 'system.multicall' xml-rpc method call to forward to the server all |
||
435 | * the requests in a single HTTP round trip, unless $this->no_multicall has |
||
436 | * been previously set to TRUE (see the multicall method below), in which case |
||
437 | * many consecutive xmlrpc requests will be sent. The method will return an |
||
438 | * array of Response objects in both cases. |
||
439 | * The third variant allows to build by hand (or any other means) a complete |
||
440 | * xmlrpc request message, and send it to the server. $req should be a string |
||
441 | * containing the complete xml representation of the request. It is e.g. useful |
||
442 | * when, for maximal speed of execution, the request is serialized into a |
||
443 | * string using the native php xmlrpc functions (see http://www.php.net/xmlrpc) |
||
444 | * @param integer $timeout Connection timeout, in seconds, If unspecified, a platform specific timeout will apply. |
||
445 | * This timeout value is passed to fsockopen(). It is also used for detecting server |
||
446 | * timeouts during communication (i.e. if the server does not send anything to the client |
||
447 | * for $timeout seconds, the connection will be closed). |
||
448 | * @param string $method valid values are 'http', 'http11' and 'https'. If left unspecified, the http protocol |
||
449 | * chosen during creation of the object will be used. |
||
450 | * |
||
451 | * @return Response|Response[] Note that the client will always return a Response object, even if the call fails |
||
452 | */ |
||
453 | public function send($req, $timeout = 0, $method = '') |
||
533 | |||
534 | /** |
||
535 | * @deprecated |
||
536 | * @param Request $req |
||
537 | * @param string $server |
||
538 | * @param int $port |
||
539 | * @param int $timeout |
||
540 | * @param string $username |
||
541 | * @param string $password |
||
542 | * @param int $authType |
||
543 | * @param string $proxyHost |
||
544 | * @param int $proxyPort |
||
545 | * @param string $proxyUsername |
||
546 | * @param string $proxyPassword |
||
547 | * @param int $proxyAuthType |
||
548 | * @param string $method |
||
549 | * @return Response |
||
550 | */ |
||
551 | protected function sendPayloadHTTP10($req, $server, $port, $timeout = 0, $username = '', $password = '', |
||
558 | |||
559 | /** |
||
560 | * @deprecated |
||
561 | * @param Request $req |
||
562 | * @param string $server |
||
563 | * @param int $port |
||
564 | * @param int $timeout |
||
565 | * @param string $username |
||
566 | * @param string $password |
||
567 | * @param int $authType |
||
568 | * @param string $cert |
||
569 | * @param string $certPass |
||
570 | * @param string $caCert |
||
571 | * @param string $caCertDir |
||
572 | * @param string $proxyHost |
||
573 | * @param int $proxyPort |
||
574 | * @param string $proxyUsername |
||
575 | * @param string $proxyPassword |
||
576 | * @param int $proxyAuthType |
||
577 | * @param bool $keepAlive |
||
578 | * @param string $key |
||
579 | * @param string $keyPass |
||
580 | * @param int $sslVersion |
||
581 | * @return Response |
||
582 | */ |
||
583 | protected function sendPayloadHTTPS($req, $server, $port, $timeout = 0, $username = '', $password = '', |
||
592 | |||
593 | /** |
||
594 | * @param Request $req |
||
595 | * @param string $server |
||
596 | * @param int $port |
||
597 | * @param int $timeout |
||
598 | * @param string $username |
||
599 | * @param string $password |
||
600 | * @param int $authType only value supported is 1 |
||
601 | * @param string $cert |
||
602 | * @param string $certPass |
||
603 | * @param string $caCert |
||
604 | * @param string $caCertDir |
||
605 | * @param string $proxyHost |
||
606 | * @param int $proxyPort |
||
607 | * @param string $proxyUsername |
||
608 | * @param string $proxyPassword |
||
609 | * @param int $proxyAuthType only value supported is 1 |
||
610 | * @param string $method 'http' (synonym for 'http10'), 'http10' or 'https' |
||
611 | * @param string $key |
||
612 | * @param string $keyPass @todo not implemented yet. |
||
613 | * @param int $sslVersion @todo not implemented yet. See http://php.net/manual/en/migration56.openssl.php |
||
614 | * @return Response |
||
615 | */ |
||
616 | protected function sendPayloadSocket($req, $server, $port, $timeout = 0, $username = '', $password = '', |
||
800 | |||
801 | /** |
||
802 | * Contributed by Justin Miller <[email protected]> |
||
803 | * Requires curl to be built into PHP |
||
804 | * NB: CURL versions before 7.11.10 cannot use proxy to talk to https servers! |
||
805 | * |
||
806 | * @param Request $req |
||
807 | * @param string $server |
||
808 | * @param int $port |
||
809 | * @param int $timeout |
||
810 | * @param string $username |
||
811 | * @param string $password |
||
812 | * @param int $authType |
||
813 | * @param string $cert |
||
814 | * @param string $certPass |
||
815 | * @param string $caCert |
||
816 | * @param string $caCertDir |
||
817 | * @param string $proxyHost |
||
818 | * @param int $proxyPort |
||
819 | * @param string $proxyUsername |
||
820 | * @param string $proxyPassword |
||
821 | * @param int $proxyAuthType |
||
822 | * @param string $method 'http' (let curl decide), 'http10', 'http11' or 'https' |
||
823 | * @param bool $keepAlive |
||
824 | * @param string $key |
||
825 | * @param string $keyPass |
||
826 | * @param int $sslVersion |
||
827 | * @return Response |
||
828 | */ |
||
829 | protected function sendPayloadCURL($req, $server, $port, $timeout = 0, $username = '', $password = '', |
||
1062 | |||
1063 | /** |
||
1064 | * Send an array of requests and return an array of responses. |
||
1065 | * |
||
1066 | * Unless $this->no_multicall has been set to true, it will try first to use one single xmlrpc call to server method |
||
1067 | * system.multicall, and revert to sending many successive calls in case of failure. |
||
1068 | * This failure is also stored in $this->no_multicall for subsequent calls. |
||
1069 | * Unfortunately, there is no server error code universally used to denote the fact that multicall is unsupported, |
||
1070 | * so there is no way to reliably distinguish between that and a temporary failure. |
||
1071 | * If you are sure that server supports multicall and do not want to fallback to using many single calls, set the |
||
1072 | * fourth parameter to FALSE. |
||
1073 | * |
||
1074 | * NB: trying to shoehorn extra functionality into existing syntax has resulted |
||
1075 | * in pretty much convoluted code... |
||
1076 | * |
||
1077 | * @param Request[] $reqs an array of Request objects |
||
1078 | * @param integer $timeout connection timeout (in seconds). See the details in the docs for the send() method |
||
1079 | * @param string $method the http protocol variant to be used. See the details in the docs for the send() method |
||
1080 | * @param boolean fallback When true, upon receiving an error during multicall, multiple single calls will be |
||
1081 | * attempted |
||
1082 | * |
||
1083 | * @return Response[] |
||
1084 | */ |
||
1085 | public function multicall($reqs, $timeout = 0, $method = '', $fallback = true) |
||
1133 | |||
1134 | /** |
||
1135 | * Attempt to boxcar $reqs via system.multicall. |
||
1136 | * |
||
1137 | * Returns either an array of Response, a single error Response or false (when received response does not respect |
||
1138 | * valid multicall syntax). |
||
1139 | * |
||
1140 | * @param Request[] $reqs |
||
1141 | * @param int $timeout |
||
1142 | * @param string $method |
||
1143 | * @return Response[]|bool|mixed|Response |
||
1144 | */ |
||
1145 | private function _try_multicall($reqs, $timeout, $method) |
||
1259 | } |
||
1260 |
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
or
||
The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&
, or||
.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
die
introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.