Hoa central
Lookahead.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Iterator;
38 
47 class Lookahead
48  extends IteratorIterator
49  implements Outer
50 {
56  protected $_iterator = null;
57 
63  protected $_key = 0;
64 
70  protected $_current = null;
71 
77  protected $_valid = false;
78 
79 
80 
87  public function __construct(\Iterator $iterator)
88  {
89  $this->_iterator = $iterator;
90 
91  return;
92  }
93 
99  public function getInnerIterator()
100  {
101  return $this->_iterator;
102  }
103 
109  public function current()
110  {
111  return $this->_current;
112  }
113 
119  public function key()
120  {
121  return $this->_key;
122  }
123 
129  public function next()
130  {
131  $innerIterator = $this->getInnerIterator();
132  $this->_valid = $innerIterator->valid();
133 
134  if (false === $this->_valid) {
135  return;
136  }
137 
138  $this->_key = $innerIterator->key();
139  $this->_current = $innerIterator->current();
140 
141  return $innerIterator->next();
142  }
143 
149  public function rewind()
150  {
151  $out = $this->getInnerIterator()->rewind();
152  $this->next();
153 
154  return $out;
155  }
156 
162  public function valid()
163  {
164  return $this->_valid;
165  }
166 
172  public function hasNext()
173  {
174  return $this->getInnerIterator()->valid();
175  }
176 
182  public function getNext()
183  {
184  return $this->getInnerIterator()->current();
185  }
186 
192  public function getNextKey()
193  {
194  return $this->getInnerIterator()->key();
195  }
196 }
__construct(\Iterator $iterator)
Definition: Lookahead.php:87