Response.php
870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace ACP\API;
use WP_Error;
class Response {
/**
* @var object
*/
private $body;
/**
* @var WP_Error
*/
private $error;
public function get_body() {
return $this->body;
}
public function get_error() {
return $this->error;
}
/**
* @return bool
*/
public function has_error() {
return $this->error instanceof WP_Error;
}
/**
* @param object $body
*
* @return Response
*/
public function with_body( $body ) {
$self = clone $this;
$self->body = $body;
return $self;
}
public function with_error( WP_Error $error ) {
$self = clone $this;
$self->error = $error;
return $self;
}
/**
* Access properties from the body
*
* @param string $key
*
* @return mixed
*/
public function get( $key ) {
if ( ! isset( $this->body->$key ) ) {
return null;
}
return $this->body->$key;
}
}