1 | <?php |
||
7 | class Filters |
||
8 | { |
||
9 | /** |
||
10 | * @var array |
||
11 | */ |
||
12 | private $filters; |
||
13 | |||
14 | /** |
||
15 | * Matches :text(value), where value is a double or single quoted string |
||
16 | * Supports single or double quotes escaping inside |
||
17 | * |
||
18 | * http://regexr.com/3bqg1 |
||
19 | * http://stackoverflow.com/questions/249791/regex-for-quoted-string-with-escaping-quotes |
||
20 | */ |
||
21 | const TEXT = '/:text\((["\'])((?:[^\1\\\\]|\\\\.)*?)\1\)/'; |
||
22 | |||
23 | /** |
||
24 | * Matches :value(value), where value is a double or single quoted string |
||
25 | * Supports single or double quotes escaping inside |
||
26 | * |
||
27 | * http://regexr.com/3bqg1 |
||
28 | * http://stackoverflow.com/questions/249791/regex-for-quoted-string-with-escaping-quotes |
||
29 | */ |
||
30 | const VALUE = '/:value\((["\'])((?:[^\1\\\\]|\\\\.)*?)\1\)/'; |
||
31 | |||
32 | /** |
||
33 | * Matches :visible(value), where value is a positive or negative string |
||
34 | * Supports true/false, on/off, yes/no, 1/0 |
||
35 | * |
||
36 | * http://stackoverflow.com/questions/7336861/how-to-convert-string-to-boolean-php |
||
37 | */ |
||
38 | const VISIBLE = '/:visible\((([\w]+))\)/'; |
||
39 | |||
40 | private static $patterns = [ |
||
41 | 'text' => Filters::TEXT, |
||
42 | 'value' => Filters::VALUE, |
||
43 | 'visible' => Filters::VISIBLE, |
||
44 | ]; |
||
45 | |||
46 | /** |
||
47 | * @return array |
||
48 | */ |
||
49 | 1 | public static function getPatterns() |
|
53 | |||
54 | /** |
||
55 | * @param array $filters |
||
56 | */ |
||
57 | 1 | public function __construct(array $filters = []) |
|
61 | |||
62 | /** |
||
63 | * @return array |
||
64 | */ |
||
65 | 1 | public function all() |
|
69 | |||
70 | /** |
||
71 | * @param string $name |
||
72 | * @param string $pattern |
||
73 | * @param string $selector |
||
74 | * @return string |
||
75 | */ |
||
76 | 1 | public function extractPattern($name, $pattern, $selector) |
|
85 | |||
86 | /** |
||
87 | * @param string $selector |
||
88 | * @return string |
||
89 | */ |
||
90 | 1 | public function extractAllPatterns($selector) |
|
98 | |||
99 | /** |
||
100 | * @param CrawlerInterface $crawler |
||
101 | * @param string $id |
||
102 | * @return boolean |
||
103 | */ |
||
104 | 2 | public function match(CrawlerInterface $crawler, $id) |
|
114 | |||
115 | /** |
||
116 | * @return boolean |
||
117 | */ |
||
118 | 1 | public function isEmpty() |
|
122 | |||
123 | /** |
||
124 | * @param CrawlerInterface $crawler |
||
125 | * @param array $ids |
||
126 | * @return array |
||
127 | */ |
||
128 | 2 | public function matchAll(CrawlerInterface $crawler, array $ids) |
|
143 | |||
144 | /** |
||
145 | * @param CrawlerInterface $crawler |
||
146 | * @param string $id |
||
147 | * @param string $value |
||
148 | * @return boolean |
||
149 | */ |
||
150 | 2 | public function value(CrawlerInterface $crawler, $id, $value) |
|
154 | |||
155 | /** |
||
156 | * @param CrawlerInterface $crawler |
||
157 | * @param string $id |
||
158 | * @param boolean $isVisible |
||
159 | * @return boolean |
||
160 | */ |
||
161 | 10 | public function visible(CrawlerInterface $crawler, $id, $isVisible = true) |
|
165 | |||
166 | /** |
||
167 | * @param CrawlerInterface $crawler |
||
168 | * @param string $id |
||
169 | * @param string $text |
||
170 | * @return string |
||
171 | */ |
||
172 | 4 | public function text(CrawlerInterface $crawler, $id, $text) |
|
176 | } |
||
177 |