1 | <?php |
||
5 | class UrlStatus { |
||
6 | |||
7 | /** |
||
8 | * Url to check |
||
9 | * |
||
10 | * @var string |
||
11 | */ |
||
12 | protected $url; |
||
13 | |||
14 | /** |
||
15 | * Status code returned, if URL is responding |
||
16 | * |
||
17 | * @var int|null |
||
18 | */ |
||
19 | protected $statusCode; |
||
20 | |||
21 | /** |
||
22 | * Reason for when URL is not responding with 200 status code |
||
23 | * |
||
24 | * @var string|null |
||
25 | */ |
||
26 | protected $reason; |
||
27 | |||
28 | /** |
||
29 | * If the url's host is unresolvable |
||
30 | * |
||
31 | * @var bool |
||
32 | */ |
||
33 | protected $unresolvableHost; |
||
34 | |||
35 | /** |
||
36 | * The Guzzle response object (if successful connection) |
||
37 | * |
||
38 | * @var \GuzzleHttp\Message\Response|null |
||
39 | */ |
||
40 | protected $response; |
||
41 | |||
42 | /** |
||
43 | * Time it took for the request in seconds |
||
44 | * |
||
45 | * @var double |
||
46 | */ |
||
47 | protected $time; |
||
48 | |||
49 | /** |
||
50 | * Create an instance of an UrlStatus |
||
51 | * |
||
52 | * @param string $url |
||
53 | * @param int|null $statusCode |
||
54 | * @param double $time in seconds |
||
55 | * @param bool $unresolvableHost |
||
56 | * @param \GuzzleHttp\Message\Response|null $response |
||
57 | * @param string|null $reason |
||
58 | */ |
||
59 | 4 | public function __construct($url, $statusCode, $time, $unresolvableHost, $response = null, $reason = null) |
|
68 | |||
69 | /** |
||
70 | * Return if the URL is responding with a 200 status |
||
71 | * |
||
72 | * @return bool |
||
73 | */ |
||
74 | 3 | public function isRespondingOk() |
|
78 | |||
79 | |||
80 | /** |
||
81 | * Return if the URL is responding but not with a 200 status code |
||
82 | * |
||
83 | * @return bool |
||
84 | */ |
||
85 | 1 | public function isRespondingButNotOk() |
|
89 | |||
90 | /** |
||
91 | * Return if the URL is not responding at all |
||
92 | * |
||
93 | * @return bool |
||
94 | */ |
||
95 | 1 | public function isNotResponding() |
|
99 | |||
100 | /** |
||
101 | * Return if the URL's host is unresolvable |
||
102 | * |
||
103 | * @return bool |
||
104 | */ |
||
105 | 1 | public function hostIsUnresolvable() |
|
109 | |||
110 | /** |
||
111 | * Get the status code returned (if successful connection) |
||
112 | * |
||
113 | * @return int|null |
||
114 | */ |
||
115 | 2 | public function getStatusCode() |
|
119 | |||
120 | /** |
||
121 | * Get the URL |
||
122 | * |
||
123 | * @return string |
||
124 | */ |
||
125 | public function getUrl() |
||
129 | |||
130 | /** |
||
131 | * Get the reason if connection was unsuccessful |
||
132 | * |
||
133 | * @return string|null |
||
134 | */ |
||
135 | public function getReason() |
||
139 | |||
140 | /** |
||
141 | * Get the time it took for the request to complete (in seconds) |
||
142 | * |
||
143 | * @return double |
||
144 | */ |
||
145 | 1 | public function getTimeInSeconds() |
|
149 | |||
150 | |||
151 | /** |
||
152 | * Get the time it took for the request to complete (in milliseconds) |
||
153 | * |
||
154 | * @return double |
||
155 | */ |
||
156 | 1 | public function getTimeInMilliSeconds() |
|
160 | |||
161 | /** |
||
162 | * Get the Guzzle response object (if successful connection) |
||
163 | * |
||
164 | * @return null|GuzzleHttp\Message\Response |
||
165 | */ |
||
166 | 1 | public function getResponse() |
|
170 | |||
171 | |||
172 | } |
||
173 |