1 | <?php |
||
14 | class Jetpack_IXR_Client extends IXR_Client { |
||
15 | public $jetpack_args = null; |
||
16 | |||
17 | function __construct( $args = array(), $path = false, $port = 80, $timeout = 15 ) { |
||
18 | $defaults = array( |
||
19 | 'url' => Jetpack::xmlrpc_api_url(), |
||
20 | 'user_id' => 0, |
||
21 | ); |
||
22 | |||
23 | $args = wp_parse_args( $args, $defaults ); |
||
24 | |||
25 | $this->jetpack_args = $args; |
||
26 | |||
27 | $this->IXR_Client( $args['url'], $path, $port, $timeout ); |
||
28 | } |
||
29 | |||
30 | function query() { |
||
31 | $args = func_get_args(); |
||
32 | $method = array_shift( $args ); |
||
33 | $request = new IXR_Request( $method, $args ); |
||
34 | $xml = trim( $request->getXml() ); |
||
35 | |||
36 | $response = Jetpack_Client::remote_request( $this->jetpack_args, $xml ); |
||
37 | |||
38 | if ( is_wp_error( $response ) ) { |
||
39 | $this->error = new IXR_Error( -10520, sprintf( 'Jetpack: [%s] %s', $response->get_error_code(), $response->get_error_message() ) ); |
||
40 | return false; |
||
41 | } |
||
42 | |||
43 | if ( !$response ) { |
||
44 | $this->error = new IXR_Error( -10520, 'Jetpack: Unknown Error' ); |
||
45 | return false; |
||
46 | } |
||
47 | |||
48 | if ( 200 != wp_remote_retrieve_response_code( $response ) ) { |
||
49 | $this->error = new IXR_Error( -32300, 'transport error - HTTP status code was not 200' ); |
||
50 | return false; |
||
51 | } |
||
52 | |||
53 | $content = wp_remote_retrieve_body( $response ); |
||
54 | |||
55 | // Now parse what we've got back |
||
56 | $this->message = new IXR_Message( $content ); |
||
57 | if ( !$this->message->parse() ) { |
||
58 | // XML error |
||
59 | $this->error = new IXR_Error( -32700, 'parse error. not well formed' ); |
||
60 | return false; |
||
61 | } |
||
62 | |||
63 | // Is the message a fault? |
||
64 | if ( $this->message->messageType == 'fault' ) { |
||
65 | $this->error = new IXR_Error( $this->message->faultCode, $this->message->faultString ); |
||
66 | return false; |
||
67 | } |
||
68 | |||
69 | // Message must be OK |
||
70 | return true; |
||
71 | } |
||
72 | |||
73 | function get_jetpack_error( $fault_code = null, $fault_string = null ) { |
||
91 | } |
||
92 | |||
93 | /** |
||
136 |
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.