Hoa central
Domain.php
Go to the documentation of this file.
1 <?php
2 
38 
39 use Hoa\Iterator;
40 
49 class Domain implements Iterator
50 {
56  protected $_variables = [];
57 
63  protected $_max = 0;
64 
70  protected $_key = 0;
71 
77  protected $_current = null;
78 
84  protected $_break = true;
85 
86 
87 
94  public function __construct($variables)
95  {
96  foreach ($variables as $variable) {
97  $this->_variables[] = $variable->getDomains()->getIterator();
98  }
99 
100  $this->_max = count($this->_variables) - 1;
101  $this->_break = empty($this->_variables);
102 
103  return;
104  }
105 
111  public function current()
112  {
113  return $this->_current;
114  }
115 
121  protected function _current()
122  {
123  $this->_current = [];
124 
125  foreach ($this->_variables as $variable) {
126  $current = $variable->current();
127  $this->_current[$current->getHolder()->getName()] = $current;
128  }
129 
130  return;
131  }
132 
138  public function key()
139  {
140  return $this->_key;
141  }
142 
148  public function next()
149  {
150  for ($i = 0; $i <= $this->_max; ++$i) {
151  $this->_variables[$i]->next();
152 
153  if (false !== $this->_variables[$i]->valid()) {
154  break;
155  }
156 
157  $this->_variables[$i]->rewind();
158 
159  if ($i === $this->_max) {
160  $this->_break = true;
161 
162  break;
163  }
164  }
165 
166  ++$this->_key;
167  $this->_current();
168 
169  return $this->current();
170  }
171 
177  public function rewind()
178  {
179  $this->_break = empty($this->_variables);
180  $this->_key = 0;
181 
182  foreach ($this->_variables as $variable) {
183  $variable->rewind();
184  }
185 
186  $this->_current();
187 
188  return $this->current();
189  }
190 
197  public function valid()
198  {
199  return false === $this->_break;
200  }
201 }