1 | <?php |
||
11 | class UriClient extends TxtClient |
||
12 | { |
||
13 | /** |
||
14 | * ANSI C's asctime() format |
||
15 | */ |
||
16 | const DATE_ASCTIME = 'D M j h:i:s Y'; |
||
17 | |||
18 | /** |
||
19 | * HTTP date formats |
||
20 | */ |
||
21 | const DATE_HTTP = [ |
||
22 | DATE_RFC1123, |
||
23 | DATE_RFC850, |
||
24 | self::DATE_ASCTIME, |
||
25 | ]; |
||
26 | |||
27 | /** |
||
28 | * GuzzleHttp config |
||
29 | */ |
||
30 | const GUZZLE_HTTP_CONFIG = [ |
||
31 | 'allow_redirects' => [ |
||
32 | 'max' => self::MAX_REDIRECTS, |
||
33 | 'referer' => true, |
||
34 | 'strict' => true, |
||
35 | ], |
||
36 | 'decode_content' => false, |
||
37 | 'headers' => [ |
||
38 | 'accept' => 'text/plain;q=1.0, text/*;q=0.8, */*;q=0.1', |
||
39 | 'accept-charset' => 'utf-8;q=1.0, *;q=0.1', |
||
40 | 'accept-encoding' => 'identity;q=1.0, *;q=0.1', |
||
41 | 'user-agent' => 'RobotsTxtParser-VIPnytt/2.0 (+https://github.com/VIPnytt/RobotsTxtParser/blob/master/README.md)', |
||
42 | ], |
||
43 | 'http_errors' => false, |
||
44 | 'verify' => true, |
||
45 | ]; |
||
46 | |||
47 | /** |
||
48 | * Base uri |
||
49 | * @var string |
||
50 | */ |
||
51 | private $base; |
||
52 | |||
53 | /** |
||
54 | * RequestClient timestamp |
||
55 | * @var int |
||
56 | */ |
||
57 | private $time; |
||
58 | |||
59 | /** |
||
60 | * @var \Psr\Http\Message\ResponseInterface |
||
61 | */ |
||
62 | private $response; |
||
63 | |||
64 | /** |
||
65 | * Cache-Control max-age |
||
66 | * @var int |
||
67 | */ |
||
68 | private $maxAge; |
||
69 | |||
70 | /** |
||
71 | * Robots.txt contents |
||
72 | * @var string |
||
73 | */ |
||
74 | private $contents; |
||
75 | |||
76 | /** |
||
77 | * Robots.txt character encoding |
||
78 | * @var string |
||
79 | */ |
||
80 | private $encoding; |
||
81 | |||
82 | /** |
||
83 | * RequestClient constructor. |
||
84 | * |
||
85 | * @param string $baseUri |
||
86 | * @param array $guzzleConfig |
||
87 | * @param int|null $byteLimit |
||
88 | */ |
||
89 | public function __construct($baseUri, array $guzzleConfig = [], $byteLimit = self::BYTE_LIMIT) |
||
117 | |||
118 | /** |
||
119 | * Content-Type encoding HTTP header |
||
120 | * |
||
121 | * @link https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17 |
||
122 | * |
||
123 | * @return string |
||
124 | */ |
||
125 | private function headerCharset() |
||
132 | |||
133 | /** |
||
134 | * Client header |
||
135 | * |
||
136 | * @param string[] $headers |
||
137 | * @param string $part |
||
138 | * @param string $delimiter |
||
139 | * @return string|false |
||
140 | */ |
||
141 | private function parseHeader(array $headers, $part, $delimiter = ";") |
||
152 | |||
153 | /** |
||
154 | * Cache-Control max-age HTTP header |
||
155 | * |
||
156 | * @link https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.3 |
||
157 | * |
||
158 | * @return int |
||
159 | */ |
||
160 | private function headerMaxAge() |
||
167 | |||
168 | /** |
||
169 | * Base UriClient |
||
170 | * |
||
171 | * @return string |
||
172 | */ |
||
173 | public function getBaseUri() |
||
177 | |||
178 | /** |
||
179 | * Status code |
||
180 | * |
||
181 | * @return int|null |
||
182 | */ |
||
183 | public function getStatusCode() |
||
187 | |||
188 | /** |
||
189 | * URL content |
||
190 | * |
||
191 | * @return string |
||
192 | */ |
||
193 | public function getContents() |
||
197 | |||
198 | /** |
||
199 | * Encoding |
||
200 | * |
||
201 | * @return string |
||
202 | */ |
||
203 | public function getEncoding() |
||
207 | |||
208 | /** |
||
209 | * Next update timestamp |
||
210 | * |
||
211 | * @return int |
||
212 | */ |
||
213 | public function nextUpdate() |
||
223 | |||
224 | /** |
||
225 | * Cache-Control Retry-After HTTP header |
||
226 | * |
||
227 | * @link https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.37 |
||
228 | * |
||
229 | * @return int|false |
||
230 | */ |
||
231 | private function headerRetryAfter() |
||
243 | |||
244 | /** |
||
245 | * Parse HTTP-date |
||
246 | * |
||
247 | * @param string $string |
||
248 | * @return int|false |
||
249 | */ |
||
250 | private function parseHttpDate($string) |
||
260 | |||
261 | /** |
||
262 | * Valid until timestamp |
||
263 | * |
||
264 | * @return int |
||
265 | */ |
||
266 | public function validUntil() |
||
270 | } |
||
271 |