15
15
* @package QL\Dom
16
16
*
17
17
* @method Elements toReference(&$var)
18
- * @method Elements documentFragment($state= null)
18
+ * @method Elements documentFragment($state = null)
19
19
* @method Elements toRoot()
20
20
* @method Elements getDocumentIDRef(&$documentID)
21
21
* @method Elements getDocument()
26
26
* @method bool isXHTML()
27
27
* @method bool isXML()
28
28
* @method string serialize()
29
- * @method array serializeArray($submit= null)
30
- * @method \DOMElement|\DOMElement[] get($index= null,$callback1= null,$callback2= null,$callback3= null)
31
- * @method string|array getString($index= null,$callback1= null,$callback2= null,$callback3= null)
32
- * @method string|array getStrings($index= null,$callback1= null,$callback2= null,$callback3= null)
33
- * @method Elements newInstance($newStack= null)
34
- * @method Elements find($selectors,$context= null,$noHistory= false)
35
- * @method Elements|bool is($selector,$nodes= null)
36
- * @method Elements filterCallback($callback,$_skipHistory= false)
37
- * @method Elements filter($selectors,$_skipHistory= false)
38
- * @method Elements load($url,$data= null,$callback= null)
39
- * @method Elements trigger($type,$data= [])
40
- * @method Elements triggerHandler($type,$data= [])
41
- * @method Elements bind($type,$data,$callback= null)
42
- * @method Elements unbind($type= null,$callback= null)
43
- * @method Elements change($callback= null)
44
- * @method Elements submit($callback= null)
45
- * @method Elements click($callback= null)
29
+ * @method array serializeArray($submit = null)
30
+ * @method \DOMElement|\DOMElement[] get($index = null, $callback1 = null, $callback2 = null, $callback3 = null)
31
+ * @method string|array getString($index = null, $callback1 = null, $callback2 = null, $callback3 = null)
32
+ * @method string|array getStrings($index = null, $callback1 = null, $callback2 = null, $callback3 = null)
33
+ * @method Elements newInstance($newStack = null)
34
+ * @method Elements find($selectors, $context = null, $noHistory = false)
35
+ * @method Elements|bool is($selector, $nodes = null)
36
+ * @method Elements filterCallback($callback, $_skipHistory = false)
37
+ * @method Elements filter($selectors, $_skipHistory = false)
38
+ * @method Elements load($url, $data = null, $callback = null)
39
+ * @method Elements trigger($type, $data = [])
40
+ * @method Elements triggerHandler($type, $data = [])
41
+ * @method Elements bind($type, $data, $callback = null)
42
+ * @method Elements unbind($type = null, $callback = null)
43
+ * @method Elements change($callback = null)
44
+ * @method Elements submit($callback = null)
45
+ * @method Elements click($callback = null)
46
46
* @method Elements wrapAllOld($wrapper)
47
47
* @method Elements wrapAll($wrapper)
48
- * @method Elements wrapAllPHP($codeBefore,$codeAfter)
48
+ * @method Elements wrapAllPHP($codeBefore, $codeAfter)
49
49
* @method Elements wrap($wrapper)
50
- * @method Elements wrapPHP($codeBefore,$codeAfter)
50
+ * @method Elements wrapPHP($codeBefore, $codeAfter)
51
51
* @method Elements wrapInner($wrapper)
52
- * @method Elements wrapInnerPHP($codeBefore,$codeAfter)
52
+ * @method Elements wrapInnerPHP($codeBefore, $codeAfter)
53
53
* @method Elements contents()
54
54
* @method Elements contentsUnwrap()
55
55
* @method Elements switchWith($markup)
56
56
* @method Elements eq($num)
57
57
* @method Elements size()
58
58
* @method Elements length()
59
59
* @method int count()
60
- * @method Elements end($level= 1)
60
+ * @method Elements end($level = 1)
61
61
* @method Elements _clone()
62
62
* @method Elements replaceWithPHP($code)
63
63
* @method Elements replaceWith($content)
64
64
* @method Elements replaceAll($selector)
65
- * @method Elements remove($selector= null)
66
- * @method Elements|string markup($markup= null,$callback1= null,$callback2= null,$callback3= null)
67
- * @method string markupOuter($callback1= null,$callback2= null,$callback3= null)
68
- * @method Elements|string html($html= null,$callback1= null,$callback2= null,$callback3= null)
69
- * @method Elements|string xml($xml= null,$callback1= null,$callback2= null,$callback3= null)
70
- * @method string htmlOuter($callback1= null,$callback2= null,$callback3= null)
71
- * @method string xmlOuter($callback1= null,$callback2= null,$callback3= null)
65
+ * @method Elements remove($selector = null)
66
+ * @method Elements|string markup($markup = null, $callback1 = null, $callback2 = null, $callback3 = null)
67
+ * @method string markupOuter($callback1 = null, $callback2 = null, $callback3 = null)
68
+ * @method Elements|string html($html = null, $callback1 = null, $callback2 = null, $callback3 = null)
69
+ * @method Elements|string xml($xml = null, $callback1 = null, $callback2 = null, $callback3 = null)
70
+ * @method string htmlOuter($callback1 = null, $callback2 = null, $callback3 = null)
71
+ * @method string xmlOuter($callback1 = null, $callback2 = null, $callback3 = null)
72
72
* @method Elements php($code)
73
73
* @method string markupPHP($code)
74
74
* @method string markupOuterPHP()
86
86
* @method Elements after($content)
87
87
* @method Elements afterPHP($content)
88
88
* @method Elements insertAfter($seletor)
89
- * @method Elements insert($target,$type)
89
+ * @method Elements insert($target, $type)
90
90
* @method int index($subject)
91
- * @method Elements slice($start,$end= null)
91
+ * @method Elements slice($start, $end = null)
92
92
* @method Elements reverse()
93
- * @method Elements|string text($text= null,$callback1= null,$callback2= null,$callback3= null)
94
- * @method Elements plugin($class,$file= null)
95
- * @method Elements _next($selector= null)
96
- * @method Elements _prev($selector= null)
97
- * @method Elements prev($selector= null)
98
- * @method Elements prevAll($selector= null)
99
- * @method Elements nextAll($selector= null)
100
- * @method Elements siblings($selector= null)
101
- * @method Elements not($selector= null)
102
- * @method Elements add($selector= null)
103
- * @method Elements parent($selector= null)
104
- * @method Elements parents($selector= null)
105
- * @method Elements stack($nodeTypes= null)
106
- * @method Elements|string attr($attr= null,$value= null)
107
- * @method Elements attrPHP($attr,$code)
93
+ * @method Elements|string text($text = null, $callback1 = null, $callback2 = null, $callback3 = null)
94
+ * @method Elements plugin($class, $file = null)
95
+ * @method Elements _next($selector = null)
96
+ * @method Elements _prev($selector = null)
97
+ * @method Elements prev($selector = null)
98
+ * @method Elements prevAll($selector = null)
99
+ * @method Elements nextAll($selector = null)
100
+ * @method Elements siblings($selector = null)
101
+ * @method Elements not($selector = null)
102
+ * @method Elements add($selector = null)
103
+ * @method Elements parent($selector = null)
104
+ * @method Elements parents($selector = null)
105
+ * @method Elements stack($nodeTypes = null)
106
+ * @method Elements|string attr($attr = null, $value = null)
107
+ * @method Elements attrPHP($attr, $code)
108
108
* @method Elements removeAttr($attr)
109
- * @method Elements|string val($val= null)
109
+ * @method Elements|string val($val = null)
110
110
* @method Elements andSelf()
111
111
* @method Elements addClass($className)
112
112
* @method Elements addClassPHP($className)
113
113
* @method bool hasClass($className)
114
114
* @method Elements removeClass($className)
115
115
* @method Elements toggleClass($className)
116
116
* @method Elements _empty()
117
- * @method Elements each($callback,$param1=null,$param2=null,$param3=null)
118
- * @method Elements callback($callback,$param1=null,$param2=null,$param3=null)
119
- * @method string data($key,$value=null)
117
+ * @method Elements callback($callback, $param1 = null, $param2 = null, $param3 = null)
118
+ * @method string data($key, $value = null)
120
119
* @method Elements removeData($key)
121
120
* @method void rewind()
122
121
* @method Elements current()
123
122
* @method int key()
124
- * @method Elements next($cssSelector= null)
123
+ * @method Elements next($cssSelector = null)
125
124
* @method bool valid()
126
125
* @method bool offsetExists($offset)
127
126
* @method Elements offsetGet($offset)
128
- * @method void offsetSet($offset,$value)
127
+ * @method void offsetSet($offset, $value)
129
128
* @method string whois($oneNode)
130
129
* @method Elements dump()
131
130
* @method Elements dumpWhois()
132
131
* @method Elements dumpLength()
133
- * @method Elements dumpTree($html,$title)
132
+ * @method Elements dumpTree($html, $title)
134
133
* @method dumpDie()
135
134
*/
136
-
137
135
class Elements
138
136
{
139
137
/**
@@ -152,15 +150,15 @@ public function __construct(phpQueryObject $elements)
152
150
153
151
public function __get ($ name )
154
152
{
155
- return property_exists ($ this ->elements ,$ name )? $ this ->elements ->$ name: $ this ->elements ->attr ($ name );
153
+ return property_exists ($ this ->elements , $ name ) ? $ this ->elements ->$ name : $ this ->elements ->attr ($ name );
156
154
}
157
155
158
156
public function __call ($ name , $ arguments )
159
157
{
160
- $ obj = call_user_func_array ([$ this ->elements ,$ name ],$ arguments );
161
- if ($ obj instanceof phpQueryObject){
158
+ $ obj = call_user_func_array ([$ this ->elements , $ name ], $ arguments );
159
+ if ($ obj instanceof phpQueryObject) {
162
160
$ obj = new self ($ obj );
163
- }else if (is_string ($ obj )){
161
+ } else if (is_string ($ obj )) {
164
162
$ obj = trim ($ obj );
165
163
}
166
164
return $ obj ;
@@ -169,27 +167,18 @@ public function __call($name, $arguments)
169
167
/**
170
168
* Iterating elements
171
169
*
172
- * @param callable $callback
170
+ * @param callable $callback
173
171
*
174
172
* @return $this
175
173
*/
176
174
public function each (callable $ callback )
177
175
{
178
- $ break = false ;
179
- $ this ->elements ->each (function ($ dom ) use ($ callback , &$ break ) {
180
- if ( ! $ dom || $ break ) {
181
- return ;
182
- }
183
- $ orig = $ dom ;
184
- $ dom = new Elements (pq ($ dom ));
185
- if (false === call_user_func ($ callback , $ dom )) {
186
- $ dom = $ orig ;
187
- $ break = true ;
188
- } else {
189
- $ dom = $ dom ->getDOMDocument ();
176
+ foreach ($ this ->elements as $ key => $ element ) {
177
+ $ break = $ callback (new self (pq ($ element )), $ key );
178
+ if ($ break === false ) {
179
+ break ;
190
180
}
191
- unset($ orig );
192
- });
181
+ }
193
182
194
183
return $ this ;
195
184
}
@@ -203,7 +192,7 @@ public function each(callable $callback)
203
192
public function map ($ callback )
204
193
{
205
194
$ collection = collect ();
206
- $ this ->elements ->each (function ($ dom ) use (& $ collection ,$ callback ){
195
+ $ this ->elements ->each (function ($ dom ) use (& $ collection , $ callback ) {
207
196
$ collection ->push ($ callback (new self (pq ($ dom ))));
208
197
});
209
198
return $ collection ;
@@ -217,7 +206,7 @@ public function map($callback)
217
206
*/
218
207
public function attrs ($ attr )
219
208
{
220
- return $ this ->map (function ($ item ) use ($ attr ){
209
+ return $ this ->map (function ($ item ) use ($ attr ) {
221
210
return $ item ->attr ($ attr );
222
211
});
223
212
}
@@ -229,7 +218,7 @@ public function attrs($attr)
229
218
*/
230
219
public function texts ()
231
220
{
232
- return $ this ->map (function ($ item ){
221
+ return $ this ->map (function ($ item ) {
233
222
return trim ($ item ->text ());
234
223
});
235
224
}
@@ -241,7 +230,7 @@ public function texts()
241
230
*/
242
231
public function htmls ()
243
232
{
244
- return $ this ->map (function ($ item ){
233
+ return $ this ->map (function ($ item ) {
245
234
return trim ($ item ->html ());
246
235
});
247
236
}
@@ -253,7 +242,7 @@ public function htmls()
253
242
*/
254
243
public function htmlOuters ()
255
244
{
256
- return $ this ->map (function ($ item ){
245
+ return $ this ->map (function ($ item ) {
257
246
return trim ($ item ->htmlOuter ());
258
247
});
259
248
}
0 commit comments