Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
NodeSet.php
Go to the documentation of this file.
1 <?php
7 
13 class NodeSet implements \Iterator, \Countable
14 {
18  private $_nodes;
19 
23  private $_current;
24 
28  private $_currentNode;
29 
33  private $count;
34 
40  public function __construct()
41  {
42  $this->_nodes = [];
43  $this->_current = 0;
44  $this->_currentNode = 0;
45  $this->count = 0;
46  }
47 
54  public function addNode(Node $node)
55  {
56  $this->_nodes[$this->_currentNode] = $node;
57  $this->count++;
58  return ++$this->_currentNode;
59  }
60 
66  public function count()
67  {
68  return $this->count;
69  }
70 
76  public function valid()
77  {
78  return isset($this->_nodes[$this->_current]);
79  }
80 
86  public function next()
87  {
88  if ($this->_current > $this->_currentNode) {
89  return false;
90  } else {
91  return $this->_current++;
92  }
93  }
94 
100  public function key()
101  {
102  return $this->_current;
103  }
104 
110  public function current()
111  {
112  return $this->_nodes[$this->_current];
113  }
114 
120  public function rewind()
121  {
122  $this->_current = 0;
123  }
124 }