1 | <?php |
||
14 | class DisAllow implements DirectiveInterface, RobotsTxtInterface |
||
15 | { |
||
16 | use Toolbox; |
||
17 | use UrlParser; |
||
18 | |||
19 | /** |
||
20 | * Directive alternatives |
||
21 | */ |
||
22 | const DIRECTIVE = [ |
||
23 | self::DIRECTIVE_ALLOW, |
||
24 | self::DIRECTIVE_DISALLOW, |
||
25 | ]; |
||
26 | |||
27 | /** |
||
28 | * Sub directives white list |
||
29 | */ |
||
30 | const SUB_DIRECTIVES = [ |
||
31 | self::DIRECTIVE_CLEAN_PARAM, |
||
32 | self::DIRECTIVE_HOST, |
||
33 | ]; |
||
34 | |||
35 | /** |
||
36 | * Directive |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $directive; |
||
40 | |||
41 | /** |
||
42 | * Rule array |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $array = []; |
||
46 | |||
47 | /** |
||
48 | * Sub-directive Clean-param |
||
49 | * @var CleanParam |
||
50 | */ |
||
51 | protected $cleanParam; |
||
52 | |||
53 | /** |
||
54 | * Sub-directive Host |
||
55 | * @var Host |
||
56 | */ |
||
57 | protected $host; |
||
58 | |||
59 | /** |
||
60 | * DisAllow constructor |
||
61 | * |
||
62 | * @param string $directive |
||
63 | */ |
||
64 | public function __construct($directive) |
||
70 | |||
71 | /** |
||
72 | * Add |
||
73 | * |
||
74 | * @param string $line |
||
75 | * @return bool |
||
76 | */ |
||
77 | public function add($line) |
||
88 | |||
89 | /** |
||
90 | * Add plain path to allow/disallow |
||
91 | * |
||
92 | * @param string $rule |
||
93 | * @return bool |
||
94 | */ |
||
95 | protected function addPath($rule) |
||
96 | { |
||
97 | if (isset($this->array['path']) && in_array($rule, $this->array['path'])) { |
||
98 | return false; |
||
99 | } |
||
100 | $this->array['path'][] = $rule; |
||
101 | return true; |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * Check |
||
106 | * |
||
107 | * @param string $url |
||
108 | * @return bool |
||
109 | */ |
||
110 | public function check($url) |
||
119 | |||
120 | /** |
||
121 | * Get path and query |
||
122 | * |
||
123 | * @param string $url |
||
124 | * @return string |
||
125 | * @throws Exceptions\ClientException |
||
126 | */ |
||
127 | protected function getPath($url) |
||
143 | |||
144 | /** |
||
145 | * Export rules |
||
146 | * |
||
147 | * @return array |
||
148 | */ |
||
149 | public function export() |
||
158 | |||
159 | /** |
||
160 | * Render |
||
161 | * |
||
162 | * @return string[] |
||
163 | */ |
||
164 | public function render() |
||
183 | } |
||
184 |