1 | <?php |
||
23 | class Parser |
||
24 | { |
||
25 | /** |
||
26 | * Registered directives. |
||
27 | * |
||
28 | * @var string[] |
||
29 | */ |
||
30 | const DIRECTIVES = [ |
||
31 | 'allow' => Directive\Allow::class, |
||
32 | 'comment' => Directive\Comment::class, |
||
33 | 'disallow' => Directive\Disallow::class, |
||
34 | 'host' => Directive\Host::class, |
||
35 | 'sitemap' => Directive\Sitemap::class, |
||
36 | 'user-agent' => Directive\UserAgent::class, |
||
37 | ]; |
||
38 | |||
39 | /** |
||
40 | * Parse robots.txt content. |
||
41 | * |
||
42 | * @param string $content |
||
43 | * |
||
44 | * @return Rulesets |
||
45 | */ |
||
46 | public function parse(string $content): Rulesets |
||
91 | |||
92 | /** |
||
93 | * Extract single rows from main content. |
||
94 | * |
||
95 | * @param string $content |
||
96 | * |
||
97 | * @return array |
||
98 | */ |
||
99 | private function extractRows(string $content): array |
||
112 | |||
113 | /** |
||
114 | * Creates a directive from the raw line contained in the robots.txt file. |
||
115 | * |
||
116 | * @param string $row Raw line |
||
117 | * |
||
118 | * @throws MissingDirectiveException If no directive is available |
||
119 | * |
||
120 | * @return DirectiveInterface |
||
121 | */ |
||
122 | private function createDirective(string $row): DirectiveInterface |
||
142 | } |
||
143 |