Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Iterator.php
Go to the documentation of this file.
1 <?php
7 
12 class Iterator implements \Iterator
13 {
19  protected $_elements;
20 
26  protected $_flyweight;
27 
33  protected $_scope;
34 
40  protected $_lastId;
41 
46  {
47  $this->_flyweight = $element;
48  }
49 
57  public function setElements(array $elements, $scope)
58  {
59  $this->_elements = $elements;
60  $this->_scope = $scope;
61  if (count($elements)) {
62  $lastElement = end($elements);
63  $this->_lastId = $lastElement['id'];
64  }
65  }
66 
72  public function current()
73  {
74  return $this->_flyweight;
75  }
76 
82  public function next()
83  {
84  next($this->_elements);
85  if (current($this->_elements)) {
86  $this->_initFlyweight(current($this->_elements));
87  if (!$this->current()->isVisible()) {
88  $this->next();
89  }
90  }
91  }
92 
99  protected function _initFlyweight(array $element)
100  {
101  $this->_flyweight->setData($element, $this->_scope);
102  }
103 
109  public function key()
110  {
111  key($this->_elements);
112  }
113 
120  public function valid()
121  {
122  return (bool)current($this->_elements);
123  }
124 
130  public function rewind()
131  {
132  reset($this->_elements);
133  if (current($this->_elements)) {
134  $this->_initFlyweight(current($this->_elements));
135  if (!$this->current()->isVisible()) {
136  $this->next();
137  }
138  }
139  }
140 
148  {
149  return $element->getId() == $this->_lastId;
150  }
151 }
__construct(\Magento\Config\Model\Config\Structure\AbstractElement $element)
Definition: Iterator.php:45
isLast(\Magento\Config\Model\Config\Structure\ElementInterface $element)
Definition: Iterator.php:147
$element
Definition: element.phtml:12