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