Hoa central
Demultiplexer.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Iterator;
38 
48 class Demultiplexer implements Iterator
49 {
55  protected $_iterator = null;
56 
62  protected $_current = null;
63 
69  protected $_demuxer = null;
70 
71 
72 
81  public function __construct(\Traversable $iterator, $demuxer)
82  {
83  if ($iterator instanceof \IteratorAggregate) {
84  $iterator = $iterator->getIterator();
85  }
86 
87  $this->_iterator = $iterator;
88  $this->_demuxer = $demuxer;
89 
90  return;
91  }
92 
98  public function current()
99  {
100  if (null !== $this->_current) {
101  return $this->_current;
102  }
103 
104  $demuxer = $this->_demuxer;
105 
106  return $this->_current = $demuxer($this->_iterator->current());
107  }
108 
114  public function key()
115  {
116  return $this->_iterator->key();
117  }
118 
124  public function next()
125  {
126  $this->_current = null;
127 
128  return $this->_iterator->next();
129  }
130 
136  public function rewind()
137  {
138  return $this->_iterator->rewind();
139  }
140 
146  public function valid()
147  {
148  return $this->_iterator->valid();
149  }
150 }
__construct(\Traversable $iterator, $demuxer)