| 1 | <?php |
||
| 13 | class AccumulateIterator implements FiniteIterableInterface |
||
| 14 | { |
||
| 15 | use FiniteIterableTrait; |
||
| 16 | |||
| 17 | /** @var \Iterator */ |
||
| 18 | protected $iterable; |
||
| 19 | |||
| 20 | /** @var \Closure */ |
||
| 21 | protected $func; |
||
| 22 | |||
| 23 | /** @var mixed */ |
||
| 24 | protected $value; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param \Iterator $iterable |
||
| 28 | * @param \Closure $func |
||
| 29 | */ |
||
| 30 | 12 | public function __construct(\Iterator $iterable, \Closure $func) |
|
| 31 | { |
||
| 32 | 12 | $this->iterable = $iterable; |
|
| 33 | 12 | $this->func = $func; |
|
| 34 | 12 | $this->value = null; |
|
| 35 | 12 | } |
|
| 36 | |||
| 37 | /** |
||
| 38 | * {@inheritDoc} |
||
| 39 | */ |
||
| 40 | 11 | public function rewind() |
|
| 41 | { |
||
| 42 | 11 | $this->iterable->rewind(); |
|
| 43 | 11 | $this->value = $this->iterable->valid() ? $this->iterable->current() : null; |
|
| 44 | 11 | } |
|
| 45 | |||
| 46 | /** |
||
| 47 | * {@inheritDoc} |
||
| 48 | */ |
||
| 49 | 9 | public function current() |
|
| 53 | |||
| 54 | /** |
||
| 55 | * {@inheritDoc} |
||
| 56 | */ |
||
| 57 | 9 | public function key() |
|
| 61 | |||
| 62 | /** |
||
| 63 | * {@inheritDoc} |
||
| 64 | */ |
||
| 65 | 9 | public function next() |
|
| 76 | |||
| 77 | /** |
||
| 78 | * {@inheritDoc} |
||
| 79 | */ |
||
| 80 | 11 | public function valid() |
|
| 84 | } |
||
| 85 |