1 | <?php |
||
10 | final class ArrayyRewindableGenerator implements \Iterator |
||
11 | { |
||
12 | /** |
||
13 | * @var callable |
||
14 | */ |
||
15 | private $generatorFunction; |
||
16 | |||
17 | /** |
||
18 | * @var \Generator |
||
19 | */ |
||
20 | private $generator; |
||
21 | |||
22 | /** |
||
23 | * @var callable|null |
||
24 | */ |
||
25 | private $onRewind; |
||
26 | |||
27 | /** |
||
28 | * @param callable $generatorConstructionFunction A callable that should return a Generator |
||
29 | * @param callable $onRewind callable that gets invoked with 0 arguments after the iterator |
||
30 | * was rewinded |
||
31 | * |
||
32 | * @throws \InvalidArgumentException |
||
33 | */ |
||
34 | 5 | public function __construct(callable $generatorConstructionFunction, callable $onRewind = null) |
|
40 | |||
41 | 5 | private function generateGenerator() |
|
49 | |||
50 | /** |
||
51 | * Return the current element. |
||
52 | * |
||
53 | * @return mixed |
||
54 | * @link http://php.net/manual/en/iterator.current.php |
||
55 | * @see Iterator::current |
||
56 | */ |
||
57 | 4 | public function current() |
|
61 | |||
62 | /** |
||
63 | * Move forward to next element. |
||
64 | * |
||
65 | * @see Iterator::next |
||
66 | * @link http://php.net/manual/en/iterator.next.php |
||
67 | */ |
||
68 | 4 | public function next() |
|
72 | |||
73 | /** |
||
74 | * Return the key of the current element. |
||
75 | * |
||
76 | * @return mixed scalar on success, or null on failure. |
||
77 | * @link http://php.net/manual/en/iterator.key.php |
||
78 | * @see Iterator::key |
||
79 | */ |
||
80 | 4 | public function key() |
|
84 | |||
85 | /** |
||
86 | * Checks if current position is valid. |
||
87 | * |
||
88 | * @return boolean |
||
89 | * @link http://php.net/manual/en/iterator.valid.php |
||
90 | * @see Iterator::rewind |
||
91 | */ |
||
92 | 5 | public function valid() |
|
96 | |||
97 | /** |
||
98 | * Rewind the Iterator to the first element. |
||
99 | * |
||
100 | * @see Iterator::rewind |
||
101 | * @link http://php.net/manual/en/iterator.rewind.php |
||
102 | */ |
||
103 | 5 | public function rewind() |
|
111 | } |
||
112 |