1 | <?php |
||
11 | class URI extends Basic |
||
12 | { |
||
13 | const GUZZLE_HTTP_CONFIG = [ |
||
14 | 'allow_redirects' => [ |
||
15 | 'max' => self::MAX_REDIRECTS, |
||
16 | 'referer' => true, |
||
17 | 'strict' => true, |
||
18 | ], |
||
19 | 'decode_content' => true, |
||
20 | 'headers' => [ |
||
21 | 'Accept' => 'text/plain;q=1.0, text/*;q=0.8, */*;q=0.1', |
||
22 | 'Accept-Charset' => 'utf-8;q=1.0, *;q=0.1', |
||
23 | 'Accept-Encoding' => 'identity;q=1.0, *;q=0.1', |
||
24 | 'User-Agent' => 'RobotsTxtParser-VIPnytt/2.0 (+https://github.com/VIPnytt/RobotsTxtParser/blob/master/README.md)', |
||
25 | ], |
||
26 | 'http_errors' => false, |
||
27 | 'verify' => true, |
||
28 | ]; |
||
29 | |||
30 | /** |
||
31 | * Status code |
||
32 | * @var int |
||
33 | */ |
||
34 | protected $statusCode; |
||
35 | |||
36 | /** |
||
37 | * RequestClient timestamp |
||
38 | * @var int |
||
39 | */ |
||
40 | private $time; |
||
41 | |||
42 | /** |
||
43 | * Cache-Control max-age |
||
44 | * @var int |
||
45 | */ |
||
46 | private $maxAge; |
||
47 | |||
48 | /** |
||
49 | * Robots.txt contents |
||
50 | * @var string |
||
51 | */ |
||
52 | private $contents; |
||
53 | |||
54 | /** |
||
55 | * Robots.txt character encoding |
||
56 | * @var string |
||
57 | */ |
||
58 | private $encoding; |
||
59 | |||
60 | /** |
||
61 | * RequestClient constructor. |
||
62 | * |
||
63 | * @param string $baseUri |
||
64 | * @param array $guzzleConfig |
||
65 | * @param int|null $byteLimit |
||
66 | */ |
||
67 | public function __construct($baseUri, array $guzzleConfig = [], $byteLimit = self::BYTE_LIMIT) |
||
94 | |||
95 | /** |
||
96 | * Content-Type encoding HTTP header |
||
97 | * |
||
98 | * @param string[] $headers |
||
99 | * @return string |
||
100 | */ |
||
101 | private function headerEncoding(array $headers) |
||
108 | |||
109 | /** |
||
110 | * Client header |
||
111 | * |
||
112 | * @param string[] $headers |
||
113 | * @param string $part |
||
114 | * @param string $delimiter |
||
115 | * @return string|false |
||
116 | */ |
||
117 | private function parseHeader(array $headers, $part, $delimiter = ";") |
||
128 | |||
129 | /** |
||
130 | * Cache-Control max-age HTTP header |
||
131 | * |
||
132 | * @param string[] $headers |
||
133 | * @return int |
||
134 | */ |
||
135 | private function headerMaxAge(array $headers) |
||
142 | |||
143 | /** |
||
144 | * Base URI |
||
145 | * |
||
146 | * @return string |
||
147 | */ |
||
148 | public function getBaseUri() |
||
152 | |||
153 | /** |
||
154 | * Status code |
||
155 | * |
||
156 | * @return int |
||
157 | */ |
||
158 | public function getStatusCode() |
||
162 | |||
163 | /** |
||
164 | * URL content |
||
165 | * |
||
166 | * @return string |
||
167 | */ |
||
168 | public function getContents() |
||
172 | |||
173 | /** |
||
174 | * Encoding |
||
175 | * |
||
176 | * @return string |
||
177 | */ |
||
178 | public function getEncoding() |
||
182 | |||
183 | /** |
||
184 | * Next update timestamp |
||
185 | * |
||
186 | * @return int |
||
187 | */ |
||
188 | public function nextUpdate() |
||
192 | |||
193 | /** |
||
194 | * Valid until timestamp |
||
195 | * |
||
196 | * @return int |
||
197 | */ |
||
198 | public function validUntil() |
||
202 | } |
||
203 |