1 | <?php |
||
17 | abstract class Parser implements RobotsTxtInterface |
||
18 | { |
||
19 | use Toolbox; |
||
20 | |||
21 | /** |
||
22 | * Directive white list |
||
23 | */ |
||
24 | const TOP_LEVEL_DIRECTIVES = [ |
||
25 | self::DIRECTIVE_CLEAN_PARAM, |
||
26 | self::DIRECTIVE_HOST, |
||
27 | self::DIRECTIVE_SITEMAP, |
||
28 | self::DIRECTIVE_USER_AGENT, |
||
29 | ]; |
||
30 | |||
31 | /** |
||
32 | * Previous directive |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $previousDirective; |
||
36 | |||
37 | /** |
||
38 | * Current user-agent(s) |
||
39 | * @var array |
||
40 | */ |
||
41 | protected $userAgentValues; |
||
42 | |||
43 | /** |
||
44 | * Clean-param class |
||
45 | * @var CleanParam |
||
46 | */ |
||
47 | protected $cleanParam; |
||
48 | |||
49 | /** |
||
50 | * Host class |
||
51 | * @var Host |
||
52 | */ |
||
53 | protected $host; |
||
54 | |||
55 | /** |
||
56 | * Sitemap class |
||
57 | * @var Sitemap |
||
58 | */ |
||
59 | protected $sitemap; |
||
60 | |||
61 | /** |
||
62 | * User-agent class |
||
63 | * @var UserAgent |
||
64 | */ |
||
65 | protected $userAgent; |
||
66 | |||
67 | /** |
||
68 | * Core constructor. |
||
69 | * |
||
70 | * @param string $content - file content |
||
71 | * @param string $encoding - character encoding |
||
72 | * @param int|null $byteLimit - maximum of bytes to parse |
||
73 | */ |
||
74 | public function __construct($content, $encoding = self::ENCODING, $byteLimit = self::BYTE_LIMIT) |
||
86 | |||
87 | /** |
||
88 | * Convert character encoding |
||
89 | * |
||
90 | * @param string $encoding |
||
91 | * @param string $content |
||
92 | * @return string |
||
93 | */ |
||
94 | protected function convertEncoding($encoding, $content) |
||
106 | |||
107 | /** |
||
108 | * Parse robots.txt |
||
109 | * |
||
110 | * @param string $txt |
||
111 | * @return void |
||
112 | */ |
||
113 | private function parseTxt($txt) |
||
126 | |||
127 | /** |
||
128 | * Add line |
||
129 | * |
||
130 | * @param string $line |
||
131 | * @return bool |
||
132 | */ |
||
133 | public function add($line) |
||
156 | |||
157 | /** |
||
158 | * Render |
||
159 | * |
||
160 | * @return string |
||
161 | */ |
||
162 | public function render() |
||
171 | |||
172 | /** |
||
173 | * Export rules |
||
174 | * |
||
175 | * @return array |
||
176 | */ |
||
177 | public function export() |
||
186 | } |
||
187 |