Response.php
866 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
<?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(): WP_Error
{
return $this->error;
}
public function has_error(): bool
{
return $this->error instanceof WP_Error;
}
public function with_body(object $body): self
{
$self = clone $this;
$self->body = $body;
return $self;
}
public function with_error(WP_Error $error): self
{
$self = clone $this;
$self->error = $error;
return $self;
}
/**
* Access properties from the body
*/
public function get($key)
{
return $this->body->{$key} ?? null;
}
}