1 | <?php |
||
11 | class InaccurateText |
||
12 | { |
||
13 | use Debugger; |
||
14 | |||
15 | /** |
||
16 | * The text, desired to be found. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | private $text = ''; |
||
21 | /** |
||
22 | * XPath query. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | private $query = ''; |
||
27 | /** |
||
28 | * The name of element's attribute (without "@" symbol). If will |
||
29 | * be specified then inaccurate search will be done in its value. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | private $attribute = ''; |
||
34 | /** |
||
35 | * An element to search in. Must be specified to performing queries. |
||
36 | * |
||
37 | * @var NodeElement |
||
38 | */ |
||
39 | private $parent; |
||
40 | |||
41 | /** |
||
42 | * @code |
||
43 | * // Any labels with text. |
||
44 | * // XPath: //label[text()] |
||
45 | * (string) (new InaccurateText)->query('//label'); |
||
46 | * @endcode |
||
47 | * |
||
48 | * @code |
||
49 | * // Any labels with "for" attribute and text(). |
||
50 | * // XPath: //label[@for][text()] |
||
51 | * (string) (new InaccurateText)->query('//label[@for]'), |
||
52 | * @endcode |
||
53 | * |
||
54 | * @code |
||
55 | * // Any labels with text, starts with "The text". |
||
56 | * // XPath: //label[text()[starts-with(., 'The text')]] |
||
57 | * (string) (new InaccurateText)->query('//label')->text('The text'); |
||
58 | * @endcode |
||
59 | * |
||
60 | * @code |
||
61 | * // Any labels with text in "data-title" attribute starts with "The text". |
||
62 | * // XPath: //label[@data-title[starts-with(., 'The text')]] |
||
63 | * (string) (new InaccurateText)->query('//label')->attribute('data-title')->text('The text'); |
||
64 | * @endcode |
||
65 | * |
||
66 | * @code |
||
67 | * // Any parent elements with text in "method" attribute starts with "POST". |
||
68 | * // XPath: /ancestor::*[@method[starts-with(., 'POST')]] |
||
69 | * (new InaccurateText)->query('/ancestor::*')->attribute('method')->text('POST'); |
||
70 | * @endcode |
||
71 | * |
||
72 | * @param string $query |
||
73 | * @param NodeElement $parent |
||
74 | */ |
||
75 | public function __construct($query, NodeElement $parent = null) |
||
84 | |||
85 | /** |
||
86 | * @return string |
||
87 | * XPath selector. |
||
88 | */ |
||
89 | public function __toString() |
||
101 | |||
102 | /** |
||
103 | * @param string $text |
||
104 | * |
||
105 | * @return $this |
||
106 | */ |
||
107 | public function text($text) |
||
113 | |||
114 | /** |
||
115 | * @param string $attribute |
||
116 | * |
||
117 | * @return $this |
||
118 | */ |
||
119 | public function attribute($attribute) |
||
125 | |||
126 | /** |
||
127 | * @return NodeElement[] |
||
128 | */ |
||
129 | public function findAll() |
||
137 | |||
138 | /** |
||
139 | * @return NodeElement |
||
140 | */ |
||
141 | public function find() |
||
147 | } |
||
148 |