1 | <?php |
||
4 | class AdblockRule |
||
5 | { |
||
6 | private $rule; |
||
7 | |||
8 | private $regex; |
||
9 | |||
10 | private $isComment = false; |
||
11 | |||
12 | private $isHtml = false; |
||
13 | |||
14 | private $isException = false; |
||
15 | |||
16 | 17 | public function __construct($rule) |
|
17 | { |
||
18 | 17 | $this->rule = $rule; |
|
19 | |||
20 | 17 | if (Str::startsWith($this->rule, '@@')) { |
|
21 | 4 | $this->isException = true; |
|
22 | 4 | $this->rule = mb_substr($this->rule, 2); |
|
23 | } |
||
24 | |||
25 | // comment |
||
26 | 17 | if (Str::startsWith($rule, '!') || Str::startsWith($rule, '[Adblock')) { |
|
27 | 5 | $this->isComment = true; |
|
28 | |||
29 | // HTML rule |
||
30 | 17 | } elseif (Str::contains($rule, '##') || Str::contains($rule, '#@#')) { |
|
31 | 2 | $this->isHtml = true; |
|
32 | |||
33 | // URI rule |
||
34 | } else { |
||
35 | 17 | $this->makeRegex(); |
|
36 | } |
||
37 | 16 | } |
|
38 | |||
39 | /** |
||
40 | * @param string $url |
||
41 | * |
||
42 | * @return boolean |
||
43 | */ |
||
44 | 10 | public function matchUrl($url) |
|
51 | |||
52 | /** |
||
53 | * @return string |
||
54 | */ |
||
55 | 15 | public function getRegex() |
|
59 | |||
60 | /** |
||
61 | * @return boolean |
||
62 | */ |
||
63 | 10 | public function isComment() |
|
67 | |||
68 | /** |
||
69 | * @return boolean |
||
70 | */ |
||
71 | 9 | public function isHtml() |
|
75 | |||
76 | /** |
||
77 | * @return boolean |
||
78 | */ |
||
79 | 9 | public function isException() |
|
83 | |||
84 | 17 | private function makeRegex() |
|
135 | } |
||
136 |