1 | <?php |
||
22 | class XRobotsTagParser |
||
23 | { |
||
24 | const HEADER_RULE_IDENTIFIER = 'x-robots-tag'; |
||
25 | const USERAGENT_DEFAULT = ''; |
||
26 | |||
27 | const DIRECTIVE_ALL = 'all'; |
||
28 | const DIRECTIVE_NONE = 'none'; |
||
29 | const DIRECTIVE_NO_ARCHIVE = 'noarchive'; |
||
30 | const DIRECTIVE_NO_FOLLOW = 'nofollow'; |
||
31 | const DIRECTIVE_NO_IMAGE_INDEX = 'noimageindex'; |
||
32 | const DIRECTIVE_NO_INDEX = 'noindex'; |
||
33 | const DIRECTIVE_NO_ODP = 'noodp'; |
||
34 | const DIRECTIVE_NO_SNIPPET = 'nosnippet'; |
||
35 | const DIRECTIVE_NO_TRANSLATE = 'notranslate'; |
||
36 | const DIRECTIVE_UNAVAILABLE_AFTER = 'unavailable_after'; |
||
37 | |||
38 | private $strict = false; |
||
|
|||
39 | |||
40 | private $url = ''; |
||
41 | private $userAgent = self::USERAGENT_DEFAULT; |
||
42 | |||
43 | private $headers = []; |
||
44 | private $currentRule = ''; |
||
45 | private $currentUserAgent = self::USERAGENT_DEFAULT; |
||
46 | private $currentDirective = ''; |
||
47 | private $currentValue = ''; |
||
48 | |||
49 | private $rules = []; |
||
50 | |||
51 | /** |
||
52 | * Constructor |
||
53 | * |
||
54 | * @param string $url |
||
55 | * @param string $userAgent |
||
56 | * @param array|null $headers |
||
57 | */ |
||
58 | public function __construct($url, $userAgent = self::USERAGENT_DEFAULT, $headers = null) |
||
74 | |||
75 | /** |
||
76 | * Request HTTP headers |
||
77 | * |
||
78 | * @param array|null|false $customHeaders - use these headers |
||
79 | * @return bool |
||
80 | */ |
||
81 | private function useHeaders($customHeaders = null) |
||
92 | |||
93 | /** |
||
94 | * Parse HTTP headers |
||
95 | * |
||
96 | * @return void |
||
97 | */ |
||
98 | private function parse() |
||
111 | |||
112 | /** |
||
113 | * Detect directives in rule |
||
114 | * |
||
115 | * @return void |
||
116 | */ |
||
117 | private function detectDirectives() |
||
134 | |||
135 | /** |
||
136 | * Directives supported |
||
137 | * |
||
138 | * @return array |
||
139 | */ |
||
140 | protected function directiveArray() |
||
155 | |||
156 | /** |
||
157 | * Add rule |
||
158 | * |
||
159 | * @return void |
||
160 | */ |
||
161 | private function addRule() |
||
169 | |||
170 | /** |
||
171 | * Cleanup before next rule is read |
||
172 | * |
||
173 | * @return void |
||
174 | */ |
||
175 | private function cleanup() |
||
182 | |||
183 | /** |
||
184 | * Return all applicable rules |
||
185 | * |
||
186 | * @return array |
||
187 | */ |
||
188 | public function getRules() |
||
202 | |||
203 | /** |
||
204 | * Export all rules for all UserAgents |
||
205 | * |
||
206 | * @return array |
||
207 | */ |
||
208 | public function export() |
||
212 | } |
This check marks private properties in classes that are never used. Those properties can be removed.