1 | <?php |
||
9 | class RewindableGenerator implements Iterator { |
||
10 | |||
11 | /** |
||
12 | * @var callable |
||
13 | */ |
||
14 | private $generatorFunction; |
||
15 | |||
16 | /** |
||
17 | * @var Generator |
||
18 | */ |
||
19 | private $generator; |
||
20 | |||
21 | /** |
||
22 | * @var callable|null |
||
23 | */ |
||
24 | private $onRewind; |
||
25 | |||
26 | /** |
||
27 | * @param callable $generatorConstructionFunction A callable that should return a Generator |
||
28 | * @param callable $onRewind callable that gets invoked with 0 arguments after the iterator was rewinded |
||
29 | * |
||
30 | * @throws InvalidArgumentException |
||
31 | */ |
||
32 | 9 | public function __construct( callable $generatorConstructionFunction, callable $onRewind = null ) { |
|
37 | |||
38 | 9 | private function generateGenerator() { |
|
45 | |||
46 | /** |
||
47 | * Return the current element |
||
48 | * @see Iterator::current |
||
49 | * @link http://php.net/manual/en/iterator.current.php |
||
50 | * @return mixed |
||
51 | */ |
||
52 | 4 | public function current() { |
|
55 | |||
56 | /** |
||
57 | * Move forward to next element |
||
58 | * @see Iterator::next |
||
59 | * @link http://php.net/manual/en/iterator.next.php |
||
60 | */ |
||
61 | 4 | public function next() { |
|
64 | |||
65 | /** |
||
66 | * Return the key of the current element |
||
67 | * @see Iterator::key |
||
68 | * @link http://php.net/manual/en/iterator.key.php |
||
69 | * @return mixed scalar on success, or null on failure. |
||
70 | */ |
||
71 | 3 | public function key() { |
|
74 | |||
75 | /** |
||
76 | * Checks if current position is valid |
||
77 | * @see Iterator::rewind |
||
78 | * @link http://php.net/manual/en/iterator.valid.php |
||
79 | * @return boolean |
||
80 | */ |
||
81 | 4 | public function valid() { |
|
84 | |||
85 | /** |
||
86 | * Rewind the Iterator to the first element |
||
87 | * @see Iterator::rewind |
||
88 | * @link http://php.net/manual/en/iterator.rewind.php |
||
89 | */ |
||
90 | 6 | public function rewind() { |
|
101 | |||
102 | /** |
||
103 | * Sets a callable that gets invoked with 0 arguments after the iterator was rewinded. |
||
104 | * If a callable has been set already, an exception will be thrown. |
||
105 | * |
||
106 | * @since 1.1.0 |
||
107 | * |
||
108 | * @param callable $onRewind |
||
109 | * @throws InvalidArgumentException |
||
110 | */ |
||
111 | 2 | public function onRewind( callable $onRewind ) { |
|
118 | |||
119 | } |
||
120 | |||
121 |