1 | <?php |
||
13 | class UserAgentParser implements ParserInterface, RobotsTxtInterface |
||
14 | { |
||
15 | use DirectiveParserCommons; |
||
16 | |||
17 | /** |
||
18 | * Sub directives white list |
||
19 | */ |
||
20 | const SUB_DIRECTIVES = [ |
||
21 | self::DIRECTIVE_ALLOW => 'allow', |
||
22 | self::DIRECTIVE_CACHE_DELAY => 'cacheDelay', |
||
23 | self::DIRECTIVE_COMMENT => 'comment', |
||
24 | self::DIRECTIVE_CRAWL_DELAY => 'crawlDelay', |
||
25 | self::DIRECTIVE_DISALLOW => 'disallow', |
||
26 | self::DIRECTIVE_REQUEST_RATE => 'requestRate', |
||
27 | self::DIRECTIVE_ROBOT_VERSION => 'robotVersion', |
||
28 | self::DIRECTIVE_VISIT_TIME => 'visitTime', |
||
29 | ]; |
||
30 | |||
31 | /** |
||
32 | * Base uri |
||
33 | * @var string |
||
34 | */ |
||
35 | private $base; |
||
36 | |||
37 | /** |
||
38 | * User-agent handler |
||
39 | * @var SubDirectiveHandler[] |
||
40 | */ |
||
41 | private $handler = []; |
||
42 | |||
43 | /** |
||
44 | * Current User-agent(s) |
||
45 | * @var string[] |
||
46 | */ |
||
47 | private $current = []; |
||
48 | |||
49 | /** |
||
50 | * Append User-agent |
||
51 | * @var bool |
||
52 | */ |
||
53 | private $append = false; |
||
54 | |||
55 | /** |
||
56 | * User-agent directive count |
||
57 | * @var int[] |
||
58 | */ |
||
59 | private $count = []; |
||
60 | |||
61 | /** |
||
62 | * User-agent client cache |
||
63 | * @var UserAgentClient[] |
||
64 | */ |
||
65 | private $client = []; |
||
66 | |||
67 | /** |
||
68 | * UserAgent constructor. |
||
69 | * |
||
70 | * @param string $base |
||
71 | */ |
||
72 | public function __construct($base) |
||
78 | |||
79 | /** |
||
80 | * Set new User-agent |
||
81 | * |
||
82 | * @param string $userAgent |
||
83 | * @return bool |
||
84 | */ |
||
85 | private function set($userAgent) |
||
103 | |||
104 | /** |
||
105 | * Add |
||
106 | * |
||
107 | * @param string $line |
||
108 | * @return bool |
||
109 | */ |
||
110 | public function add($line) |
||
127 | |||
128 | /** |
||
129 | * Render |
||
130 | * |
||
131 | * @return string[] |
||
132 | */ |
||
133 | public function render() |
||
161 | |||
162 | /** |
||
163 | * User-agent list |
||
164 | * |
||
165 | * @return string[] |
||
166 | */ |
||
167 | public function getUserAgents() |
||
173 | |||
174 | /** |
||
175 | * Export |
||
176 | * |
||
177 | * @return array |
||
178 | */ |
||
179 | public function export() |
||
187 | |||
188 | /** |
||
189 | * Client |
||
190 | * |
||
191 | * @param string $userAgent |
||
192 | * @param int|null $statusCode |
||
193 | * @return UserAgentClient |
||
194 | */ |
||
195 | public function client($userAgent = self::USER_AGENT, $statusCode = null) |
||
207 | } |
||
208 |