ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilHtmlDomNodeIterator.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
9 {
11  protected $position = 0;
12 
14  protected $nodeList;
15 
20  public function __construct(\DOMNode $el)
21  {
22  $this->position = 0;
23  if ($el instanceof \DOMDocument) {
24  $root = $el->documentElement;
25  } else {
26  if ($el instanceof \DOMElement) {
27  $root = $el;
28  } else {
29  throw new \InvalidArgumentException("Invalid arguments, expected DOMElement or DOMDocument");
30  }
31  }
32 
33  $this->nodeList = $root->childNodes;
34  }
35 
39  public function key()
40  {
41  return $this->position;
42  }
43 
47  public function next()
48  {
49  $this->position++;
50  }
51 
56  public function current()
57  {
58  return $this->nodeList->item($this->position);
59  }
60 
64  public function valid()
65  {
66  return $this->position < $this->nodeList->length;
67  }
68 
72  public function rewind()
73  {
74  $this->position = 0;
75  }
76 
80  public function hasChildren()
81  {
82  return $this->current()->hasChildNodes();
83  }
84 
88  public function getChildren()
89  {
90  return new self($this->current());
91  }
92 }
__construct(\DOMNode $el)
ilHtmlDomNodeIterator constructor.
$root
Definition: sabredav.php:45
Class ilHtmlDomNodeIterator.