1 | <?php |
||
49 | class DOMIterator extends \ArrayIterator implements \RecursiveIterator |
||
50 | { |
||
51 | /** |
||
52 | * Registered contexts |
||
53 | * |
||
54 | * @var ContextInterface[] |
||
55 | */ |
||
56 | public $contexts = []; |
||
57 | /** |
||
58 | * Element processor |
||
59 | * |
||
60 | * @var ElementProcessorInterface |
||
61 | */ |
||
62 | protected $elementProcessor; |
||
63 | /** |
||
64 | * Initial parser context |
||
65 | * |
||
66 | * @var ContextInterface |
||
67 | */ |
||
68 | protected $initialContext; |
||
69 | /** |
||
70 | * Element context map |
||
71 | * |
||
72 | * @var array |
||
73 | */ |
||
74 | protected $contextMap = []; |
||
75 | |||
76 | /** |
||
77 | * Recursive DOM node iterator constructor |
||
78 | * |
||
79 | * @param \DOMNodeList|array $nodeList Node list |
||
80 | * @param ContextInterface $initialContext Initial parser context |
||
81 | * @param ElementProcessorInterface $elementProcessor Element processor |
||
82 | */ |
||
83 | 19 | public function __construct( |
|
93 | |||
94 | /** |
||
95 | * Recursive DOM node iterator constructor |
||
96 | * |
||
97 | * @param \DOMNodeList|array $nodeList Node list |
||
98 | * @throws RuntimeException If the node list is invalid |
||
99 | * @return array Nodes |
||
100 | */ |
||
101 | 19 | protected function registerNodes($nodeList) |
|
118 | |||
119 | /** |
||
120 | * Register an element node |
||
121 | * |
||
122 | * @param \DOMNode $node Node |
||
123 | * @return \DOMNode Node |
||
124 | */ |
||
125 | 18 | protected function registerNode(\DOMNode $node) |
|
142 | |||
143 | /** |
||
144 | * Return the recursive iterator |
||
145 | * |
||
146 | * @return \RecursiveIteratorIterator Recursive iterator |
||
147 | */ |
||
148 | 18 | public function getRecursiveIterator() |
|
152 | |||
153 | /** |
||
154 | * Return whether the current node has child nodes |
||
155 | * |
||
156 | * This method gets called once per element and prior to the call to current(), |
||
157 | * so this seems like the perfect place for the first processing steps (even |
||
158 | * for elements without children). |
||
159 | * |
||
160 | * @return boolean Current node has child nodes |
||
161 | */ |
||
162 | 18 | public function hasChildren() |
|
166 | |||
167 | /** |
||
168 | * Return a child node iterator |
||
169 | * |
||
170 | * @return DOMIterator Child node iterator |
||
171 | */ |
||
172 | 18 | public function getChildren() |
|
173 | { |
||
174 | 18 | $element = $this->current(); |
|
175 | 18 | $childContext = $this->elementProcessor->processElementChildren( |
|
176 | $element, |
||
177 | 18 | $this->contexts[$this->contextMap[$this->key()]] |
|
178 | ); |
||
179 | 18 | return new static($element->childNodes, $childContext, $this->elementProcessor); |
|
180 | } |
||
181 | |||
182 | /** |
||
183 | * Rewind array back to the start |
||
184 | * |
||
185 | * @return void |
||
186 | */ |
||
187 | 18 | public function rewind() |
|
191 | } |
||
192 |