1 | <?php |
||
14 | class UserAgentClient implements RobotsTxtInterface |
||
15 | { |
||
16 | use UrlParser; |
||
17 | |||
18 | /** |
||
19 | * Rules |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $rules; |
||
23 | |||
24 | /** |
||
25 | * User-agent |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $userAgent; |
||
29 | |||
30 | /** |
||
31 | * Robots.txt base URL |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $base; |
||
35 | |||
36 | /** |
||
37 | * Status code parser |
||
38 | * @var StatusCodeParser |
||
39 | */ |
||
40 | protected $statusCodeParser; |
||
41 | |||
42 | /** |
||
43 | * UserAgentClient constructor. |
||
44 | * |
||
45 | * @param array $rules |
||
46 | * @param string $userAgent |
||
47 | * @param string $baseUrl |
||
48 | * @param int $statusCode |
||
49 | */ |
||
50 | public function __construct($rules, $userAgent, $baseUrl, $statusCode) |
||
57 | |||
58 | /** |
||
59 | * Check if URL is allowed to crawl |
||
60 | * |
||
61 | * @param string $url |
||
62 | * @return bool |
||
63 | */ |
||
64 | public function isAllowed($url) |
||
68 | |||
69 | /** |
||
70 | * Check |
||
71 | * |
||
72 | * @param string $directive |
||
73 | * @param string $url - URL to check |
||
74 | * @return bool |
||
75 | * @throws ClientException |
||
76 | */ |
||
77 | protected function check($directive, $url) |
||
95 | |||
96 | /** |
||
97 | * Check if the URL belongs to current robots.txt |
||
98 | * |
||
99 | * @param $urls |
||
100 | * @return bool |
||
101 | */ |
||
102 | protected function isUrlApplicable($urls) |
||
116 | |||
117 | /** |
||
118 | * Check if URL is disallowed to crawl |
||
119 | * |
||
120 | * @param string $url |
||
121 | * @return bool |
||
122 | */ |
||
123 | public function isDisallowed($url) |
||
127 | |||
128 | /** |
||
129 | * Get Cache-delay |
||
130 | * |
||
131 | * @return float|int |
||
132 | */ |
||
133 | public function getCacheDelay() |
||
138 | |||
139 | /** |
||
140 | * Get Crawl-delay |
||
141 | * |
||
142 | * @return float|int |
||
143 | */ |
||
144 | public function getCrawlDelay() |
||
149 | |||
150 | /** |
||
151 | * Rule export |
||
152 | * |
||
153 | * @return array |
||
154 | */ |
||
155 | public function export() |
||
165 | } |
||
166 |