1 | <?php |
||
24 | class TxtClient extends RobotsTxtParser |
||
25 | { |
||
26 | /** |
||
27 | * Status code |
||
28 | * @var int|null |
||
29 | */ |
||
30 | private $statusCode; |
||
31 | |||
32 | /** |
||
33 | * Robots.txt content |
||
34 | * @var string |
||
35 | */ |
||
36 | private $content; |
||
37 | |||
38 | /** |
||
39 | * Encoding |
||
40 | * @var string |
||
41 | */ |
||
42 | private $encoding; |
||
43 | |||
44 | /** |
||
45 | * TxtClient constructor. |
||
46 | * |
||
47 | * @param string $baseUri |
||
48 | * @param int|null $statusCode |
||
49 | * @param string $content |
||
50 | * @param string|null $encoding |
||
51 | * @param string|null $effectiveUri |
||
52 | * @param int|null $byteLimit |
||
53 | */ |
||
54 | public function __construct( |
||
55 | $baseUri, |
||
56 | $statusCode, |
||
57 | $content, |
||
58 | $encoding = self::ENCODING, |
||
59 | $effectiveUri = null, |
||
60 | $byteLimit = self::BYTE_LIMIT |
||
61 | ) |
||
62 | { |
||
63 | $this->statusCode = $statusCode; |
||
64 | $this->content = $content; |
||
65 | $this->encoding = ($encoding === null ? self::ENCODING : $encoding); |
||
66 | $this->convertEncoding(); |
||
67 | $this->limitBytes($byteLimit); |
||
68 | parent::__construct($baseUri, $this->content, $effectiveUri); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Convert character encoding |
||
73 | * |
||
74 | * @return string |
||
75 | */ |
||
76 | private function convertEncoding() |
||
87 | |||
88 | /** |
||
89 | * Byte limit |
||
90 | * |
||
91 | * @param int|null $bytes |
||
92 | * @return string |
||
93 | * @throws \InvalidArgumentException |
||
94 | */ |
||
95 | private function limitBytes($bytes) |
||
105 | |||
106 | /** |
||
107 | * Get User-agent list |
||
108 | * |
||
109 | * @return string[] |
||
110 | */ |
||
111 | public function getUserAgents() |
||
115 | |||
116 | /** |
||
117 | * Clean-param |
||
118 | * |
||
119 | * @return CleanParamClient |
||
120 | */ |
||
121 | public function cleanParam() |
||
125 | |||
126 | /** |
||
127 | * Host |
||
128 | * |
||
129 | * @return HostClient |
||
130 | */ |
||
131 | public function host() |
||
135 | |||
136 | /** |
||
137 | * Sitemaps |
||
138 | * |
||
139 | * @return SitemapClient |
||
140 | */ |
||
141 | public function sitemap() |
||
145 | |||
146 | /** |
||
147 | * User-agent specific rules |
||
148 | * |
||
149 | * @param string $product |
||
150 | * @param float|int|string|null $version |
||
151 | * @return UserAgentClient |
||
152 | */ |
||
153 | public function userAgent($product = self::USER_AGENT, $version = null) |
||
157 | } |
||
158 |