1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* This file is part of the O2System Framework package.
|
4
|
|
|
*
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE
|
6
|
|
|
* file that was distributed with this source code.
|
7
|
|
|
*
|
8
|
|
|
* @author Steeve Andrian Salim
|
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim
|
10
|
|
|
*/
|
11
|
|
|
|
12
|
|
|
// ------------------------------------------------------------------------
|
13
|
|
|
|
14
|
|
|
namespace O2System\Html\Dom\Lists;
|
15
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------
|
17
|
|
|
|
18
|
|
|
use O2System\Html\Dom\Element;
|
19
|
|
|
use RecursiveIterator;
|
20
|
|
|
|
21
|
|
|
/**
|
22
|
|
|
* Class Node
|
23
|
|
|
*
|
24
|
|
|
* @package O2System\HTML\DOM\Lists
|
25
|
|
|
*/
|
26
|
|
|
class Nodes extends \ArrayIterator implements \RecursiveIterator
|
27
|
|
|
{
|
28
|
|
|
/**
|
29
|
|
|
* Nodes::$length
|
30
|
|
|
*
|
31
|
|
|
* @var int
|
32
|
|
|
*/
|
33
|
|
|
public $length = 0;
|
34
|
|
|
|
35
|
|
|
// ------------------------------------------------------------------------
|
36
|
|
|
|
37
|
|
|
/**
|
38
|
|
|
* Nodes::__construct
|
39
|
|
|
*
|
40
|
|
|
* @param \DOMNodeList $nodeList
|
41
|
|
|
*/
|
42
|
|
|
public function __construct(\DOMNodeList $nodeList)
|
43
|
|
|
{
|
44
|
|
|
$nodes = [];
|
45
|
|
|
|
46
|
|
|
foreach ($nodeList as $node) {
|
47
|
|
|
$this->length++;
|
48
|
|
|
$nodes[] = $node;
|
49
|
|
|
}
|
50
|
|
|
|
51
|
|
|
parent::__construct($nodes);
|
52
|
|
|
}
|
53
|
|
|
|
54
|
|
|
// ------------------------------------------------------------------------
|
55
|
|
|
|
56
|
|
|
/**
|
57
|
|
|
* Nodes::item
|
58
|
|
|
*
|
59
|
|
|
* @param string $offset
|
60
|
|
|
*
|
61
|
|
|
* @return mixed
|
62
|
|
|
*/
|
63
|
|
|
public function item($offset)
|
64
|
|
|
{
|
65
|
|
|
return $this->offsetGet($offset);
|
66
|
|
|
}
|
67
|
|
|
|
68
|
|
|
// ------------------------------------------------------------------------
|
69
|
|
|
|
70
|
|
|
/**
|
71
|
|
|
* Nodes::hasChildren
|
72
|
|
|
*
|
73
|
|
|
* Returns if an iterator can be created for the current entry.
|
74
|
|
|
*
|
75
|
|
|
* @link http://php.net/manual/en/recursiveiterator.haschildren.php
|
76
|
|
|
* @return bool true if the current entry can be iterated over, otherwise returns false.
|
77
|
|
|
* @since 5.1.0
|
78
|
|
|
*/
|
79
|
|
|
public function hasChildren()
|
80
|
|
|
{
|
81
|
|
|
return $this->current()->hasChildNodes();
|
82
|
|
|
}
|
83
|
|
|
|
84
|
|
|
// ------------------------------------------------------------------------
|
85
|
|
|
|
86
|
|
|
/**
|
87
|
|
|
* Nodes::getChildren
|
88
|
|
|
*
|
89
|
|
|
* Returns an iterator for the current entry.
|
90
|
|
|
*
|
91
|
|
|
* @link http://php.net/manual/en/recursiveiterator.getchildren.php
|
92
|
|
|
* @return RecursiveIterator An iterator for the current entry.
|
93
|
|
|
* @since 5.1.0
|
94
|
|
|
*/
|
95
|
|
|
public function getChildren()
|
96
|
|
|
{
|
97
|
|
|
return new self($this->current()->childNodes);
|
98
|
|
|
}
|
99
|
|
|
|
100
|
|
|
// ------------------------------------------------------------------------
|
101
|
|
|
|
102
|
|
|
/**
|
103
|
|
|
* Nodes::replace
|
104
|
|
|
*
|
105
|
|
|
* @param mixed $source
|
106
|
|
|
*/
|
107
|
|
|
public function replace($source)
|
108
|
|
|
{
|
109
|
|
|
foreach ($this as $node) {
|
110
|
|
|
if ($node instanceof Element) {
|
111
|
|
|
$node->replace($source);
|
112
|
|
|
}
|
113
|
|
|
}
|
114
|
|
|
}
|
115
|
|
|
|
116
|
|
|
// ------------------------------------------------------------------------
|
117
|
|
|
|
118
|
|
|
/**
|
119
|
|
|
* Nodes::remove
|
120
|
|
|
*/
|
121
|
|
|
public function remove()
|
122
|
|
|
{
|
123
|
|
|
foreach ($this as $node) {
|
124
|
|
|
if ($node instanceof Element) {
|
125
|
|
|
if ( ! empty($node->parentNode)) {
|
126
|
|
|
$node->parentNode->removeChild($node);
|
127
|
|
|
}
|
128
|
|
|
}
|
129
|
|
|
}
|
130
|
|
|
}
|
131
|
|
|
|
132
|
|
|
// ------------------------------------------------------------------------
|
133
|
|
|
|
134
|
|
|
/**
|
135
|
|
|
* Nodes::prepend
|
136
|
|
|
*
|
137
|
|
|
* @param mixed $source
|
138
|
|
|
*
|
139
|
|
|
* @return static
|
140
|
|
|
*/
|
141
|
|
|
public function prepend($source)
|
142
|
|
|
{
|
143
|
|
|
foreach ($this as $node) {
|
144
|
|
|
if ($node instanceof Element) {
|
145
|
|
|
$node->append($source);
|
146
|
|
|
}
|
147
|
|
|
}
|
148
|
|
|
|
149
|
|
|
return $this;
|
150
|
|
|
}
|
151
|
|
|
|
152
|
|
|
// ------------------------------------------------------------------------
|
153
|
|
|
|
154
|
|
|
/**
|
155
|
|
|
* Nodes::append
|
156
|
|
|
*
|
157
|
|
|
* @param mixed $source
|
158
|
|
|
*
|
159
|
|
|
* @return static
|
160
|
|
|
*/
|
161
|
|
|
public function append($source)
|
162
|
|
|
{
|
163
|
|
|
foreach ($this as $node) {
|
164
|
|
|
if ($node instanceof Element) {
|
165
|
|
|
$node->prepend($source);
|
166
|
|
|
}
|
167
|
|
|
}
|
168
|
|
|
|
169
|
|
|
return $this;
|
170
|
|
|
}
|
171
|
|
|
|
172
|
|
|
// ------------------------------------------------------------------------
|
173
|
|
|
|
174
|
|
|
/**
|
175
|
|
|
* Nodes::before
|
176
|
|
|
*
|
177
|
|
|
* @param mixed $source
|
178
|
|
|
*
|
179
|
|
|
* @return static
|
180
|
|
|
*/
|
181
|
|
|
public function before($source)
|
182
|
|
|
{
|
183
|
|
|
foreach ($this as $node) {
|
184
|
|
|
if ($node instanceof Element) {
|
185
|
|
|
$node->before($source);
|
186
|
|
|
}
|
187
|
|
|
}
|
188
|
|
|
|
189
|
|
|
return $this;
|
190
|
|
|
}
|
191
|
|
|
|
192
|
|
|
// ------------------------------------------------------------------------
|
193
|
|
|
|
194
|
|
|
/**
|
195
|
|
|
* Nodes::after
|
196
|
|
|
*
|
197
|
|
|
* @param mixed $source
|
198
|
|
|
*
|
199
|
|
|
* @return static
|
200
|
|
|
*/
|
201
|
|
|
public function after($source)
|
202
|
|
|
{
|
203
|
|
|
foreach ($this as $node) {
|
204
|
|
|
if ($node instanceof Element) {
|
205
|
|
|
$node->after($source);
|
206
|
|
|
}
|
207
|
|
|
}
|
208
|
|
|
|
209
|
|
|
return $this;
|
210
|
|
|
}
|
211
|
|
|
|
212
|
|
|
// ------------------------------------------------------------------------
|
213
|
|
|
|
214
|
|
|
/**
|
215
|
|
|
* Nodes::__empty
|
216
|
|
|
*
|
217
|
|
|
* @return static
|
218
|
|
|
*/
|
219
|
|
|
public function __empty()
|
220
|
|
|
{
|
221
|
|
|
foreach ($this as $node) {
|
222
|
|
|
if ($node instanceof Element) {
|
223
|
|
|
$node->empty();
|
|
|
|
|
224
|
|
|
}
|
225
|
|
|
}
|
226
|
|
|
|
227
|
|
|
return $this;
|
228
|
|
|
}
|
229
|
|
|
|
230
|
|
|
// ------------------------------------------------------------------------
|
231
|
|
|
|
232
|
|
|
/**
|
233
|
|
|
* Nodes::__clone
|
234
|
|
|
*
|
235
|
|
|
* @return \O2System\Html\Dom\Lists\Nodes
|
236
|
|
|
*/
|
237
|
|
|
public function __clone()
|
238
|
|
|
{
|
239
|
|
|
return clone $this;
|
240
|
|
|
}
|
241
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.