1
|
|
|
<?php |
2
|
|
|
namespace vipnytt\RobotsTxtParser\Client\Directives; |
3
|
|
|
|
4
|
|
|
use vipnytt\RobotsTxtParser\Parser\Directives\SubDirectiveHandler; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class UserAgentClient |
8
|
|
|
* |
9
|
|
|
* @package vipnytt\RobotsTxtParser\Client\Directives |
10
|
|
|
*/ |
11
|
|
|
class UserAgentClient extends Checks |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Rules |
15
|
|
|
* @var SubDirectiveHandler |
16
|
|
|
*/ |
17
|
|
|
private $handler; |
|
|
|
|
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* UserAgentClient constructor. |
21
|
|
|
* |
22
|
|
|
* @param SubDirectiveHandler $handler |
23
|
|
|
* @param string $baseUri |
24
|
|
|
* @param int|null $statusCode |
25
|
|
|
*/ |
26
|
|
|
public function __construct(SubDirectiveHandler $handler, $baseUri, $statusCode) |
27
|
|
|
{ |
28
|
|
|
$this->handler = $handler; |
29
|
|
|
parent::__construct($baseUri, $statusCode, $this->handler); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* UserAgentClient destructor. |
34
|
|
|
*/ |
35
|
|
|
public function __destruct() |
36
|
|
|
{ |
37
|
|
|
$this->comment(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Comment |
42
|
|
|
* |
43
|
|
|
* @return CommentClient |
44
|
|
|
*/ |
45
|
|
|
public function comment() |
46
|
|
|
{ |
47
|
|
|
return $this->handler->comment()->client(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Allow |
52
|
|
|
* |
53
|
|
|
* @return DisAllowClient |
54
|
|
|
*/ |
55
|
|
|
public function allow() |
56
|
|
|
{ |
57
|
|
|
return $this->handler->allow()->client(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Cache-delay |
62
|
|
|
* |
63
|
|
|
* @return DelayClient |
64
|
|
|
*/ |
65
|
|
|
public function cacheDelay() |
66
|
|
|
{ |
67
|
|
|
return $this->handler->cacheDelay()->client($this->crawlDelay()->get()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Crawl-delay |
72
|
|
|
* |
73
|
|
|
* @return DelayClient |
74
|
|
|
*/ |
75
|
|
|
public function crawlDelay() |
76
|
|
|
{ |
77
|
|
|
return $this->handler->crawlDelay()->client($this->requestRate()->get()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* RequestClient-rate |
82
|
|
|
* |
83
|
|
|
* @return RequestRateClient |
84
|
|
|
*/ |
85
|
|
|
public function requestRate() |
86
|
|
|
{ |
87
|
|
|
return $this->handler->requestRate()->client(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Disallow |
92
|
|
|
* |
93
|
|
|
* @return DisAllowClient |
94
|
|
|
*/ |
95
|
|
|
public function disallow() |
96
|
|
|
{ |
97
|
|
|
return $this->handler->disallow()->client(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Robot-version |
102
|
|
|
* |
103
|
|
|
* @return RobotVersionClient |
104
|
|
|
*/ |
105
|
|
|
public function robotVersion() |
106
|
|
|
{ |
107
|
|
|
return $this->handler->robotVersion()->client(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Rule export |
112
|
|
|
* |
113
|
|
|
* @return array |
114
|
|
|
*/ |
115
|
|
|
public function getRules() |
116
|
|
|
{ |
117
|
|
|
return array_merge( |
118
|
|
|
$this->handler->allow()->getRules(), |
119
|
|
|
$this->handler->comment()->getRules(), |
120
|
|
|
$this->handler->cacheDelay()->getRules(), |
121
|
|
|
$this->handler->crawlDelay()->getRules(), |
122
|
|
|
$this->handler->disallow()->getRules(), |
123
|
|
|
$this->handler->requestRate()->getRules(), |
124
|
|
|
$this->handler->robotVersion()->getRules(), |
125
|
|
|
$this->handler->visitTime()->getRules() |
126
|
|
|
); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Visit-time |
131
|
|
|
* |
132
|
|
|
* @return VisitTimeClient |
133
|
|
|
*/ |
134
|
|
|
public function visitTime() |
135
|
|
|
{ |
136
|
|
|
return $this->handler->visitTime()->client(); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|