|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Trucker\Responses\Interpreters; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Container\Container; |
|
6
|
|
|
use Trucker\Facades\Config; |
|
7
|
|
|
use Trucker\Responses\BaseResponse; |
|
8
|
|
|
use Trucker\Support\Str; |
|
9
|
|
|
|
|
10
|
|
|
class HttpStatusCodeInterpreter implements ResponseInterpreterInterface |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* The IoC Container. |
|
14
|
|
|
* |
|
15
|
|
|
* @var Container |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $app; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Constructor to setup the interpreter. |
|
21
|
|
|
* |
|
22
|
|
|
* @param Container $app |
|
23
|
|
|
*/ |
|
24
|
24 |
|
public function __construct(Container $app) |
|
25
|
|
|
{ |
|
26
|
24 |
|
$this->app = $app; |
|
27
|
24 |
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Function to return a boolean value indicating whether |
|
31
|
|
|
* the request was successful or not. |
|
32
|
|
|
* |
|
33
|
|
|
* @param $response - Guzzle response to interpret |
|
34
|
|
|
* |
|
35
|
|
|
* @return bool |
|
36
|
|
|
*/ |
|
|
|
|
|
|
37
|
7 |
|
public function success(BaseResponse $response) |
|
38
|
|
|
{ |
|
39
|
7 |
|
return $this->matchesStatus('response.http_status.success', $response->getStatusCode()); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Function to return a boolean value indicating whether |
|
44
|
|
|
* the request indicated something was not found. |
|
45
|
|
|
* |
|
46
|
|
|
* @param $response - Guzzle response to interpret |
|
47
|
|
|
* |
|
48
|
|
|
* @return bool |
|
49
|
|
|
*/ |
|
|
|
|
|
|
50
|
1 |
|
public function notFound(BaseResponse $response) |
|
51
|
|
|
{ |
|
52
|
1 |
|
return $this->matchesStatus('response.http_status.not_found', $response->getStatusCode()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Function to return a boolean value indicating whether |
|
57
|
|
|
* the request was considered invalid. |
|
58
|
|
|
* |
|
59
|
|
|
* @param $response - Guzzle response to interpret |
|
60
|
|
|
* |
|
61
|
|
|
* @return bool |
|
62
|
|
|
*/ |
|
|
|
|
|
|
63
|
16 |
|
public function invalid(BaseResponse $response) |
|
64
|
|
|
{ |
|
65
|
16 |
|
return $this->matchesStatus('response.http_status.invalid', $response->getStatusCode()); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Function to return a boolean value indicating whether |
|
70
|
|
|
* the request was ended in an error state. |
|
71
|
|
|
* |
|
72
|
|
|
* @param $response - Guzzle response to interpret |
|
73
|
|
|
* |
|
74
|
|
|
* @return bool |
|
75
|
|
|
*/ |
|
|
|
|
|
|
76
|
1 |
|
public function error(BaseResponse $response) |
|
77
|
|
|
{ |
|
78
|
1 |
|
return $this->matchesStatus('response.http_status.error', $response->getStatusCode()); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Function to return a boolean value indicating whether |
|
83
|
|
|
* the provided status is matched by the configured setting. |
|
84
|
|
|
* |
|
85
|
|
|
* Currently supports: |
|
86
|
|
|
* |
|
87
|
|
|
* @param $option |
|
88
|
|
|
* @param $status |
|
89
|
|
|
* |
|
90
|
|
|
* @return bool |
|
91
|
|
|
*/ |
|
92
|
23 |
|
protected function matchesStatus($option, $status) |
|
93
|
|
|
{ |
|
94
|
23 |
|
$configValue = Config::get($option); |
|
|
|
|
|
|
95
|
23 |
|
if (is_array($configValue)) { |
|
96
|
4 |
|
return Config::contains($option, $status); |
|
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
23 |
|
return Str::is($configValue, $status); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|