1 | <?php |
||
20 | class RequestRateParser implements ParserInterface, RobotsTxtInterface |
||
21 | { |
||
22 | use DirectiveParserTrait; |
||
23 | |||
24 | /** |
||
25 | * Base uri |
||
26 | * @var string |
||
27 | */ |
||
28 | private $base; |
||
29 | |||
30 | /** |
||
31 | * RequestRate array |
||
32 | * @var array |
||
33 | */ |
||
34 | private $requestRates = []; |
||
35 | |||
36 | /** |
||
37 | * RequestRate constructor. |
||
38 | * |
||
39 | * @param string $base |
||
40 | */ |
||
41 | public function __construct($base) |
||
45 | |||
46 | /** |
||
47 | * Add |
||
48 | * |
||
49 | * @param string $line |
||
50 | * @return bool |
||
51 | */ |
||
52 | public function add($line) |
||
70 | |||
71 | /** |
||
72 | * Client rate as specified in the `Robot exclusion standard` version 2.0 draft |
||
73 | * rate = numDocuments / timeUnit |
||
74 | * @link http://www.conman.org/people/spc/robots2.html#format.directives.request-rate |
||
75 | * |
||
76 | * @param string $string |
||
77 | * @return float|int|false |
||
78 | */ |
||
79 | private function draftParseRate($string) |
||
102 | |||
103 | /** |
||
104 | * Client |
||
105 | * |
||
106 | * @param string $userAgent |
||
107 | * @param float|int $fallbackValue |
||
108 | * @return RequestRateClient |
||
109 | */ |
||
110 | public function client($userAgent = self::USER_AGENT, $fallbackValue = 0) |
||
115 | |||
116 | /** |
||
117 | * Sort |
||
118 | * |
||
119 | * @return void |
||
120 | */ |
||
121 | private function sort() |
||
128 | |||
129 | /** |
||
130 | * Render |
||
131 | * |
||
132 | * @param RenderHandler $handler |
||
133 | * @return bool |
||
134 | */ |
||
135 | public function render(RenderHandler $handler) |
||
149 | } |
||
150 |