| 1 | <?php |
||
| 15 | class CallbackIterator implements \Iterator |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var callback Callback for returning current element |
||
| 19 | */ |
||
| 20 | protected $current; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var callback Callback for validating next element |
||
| 24 | */ |
||
| 25 | protected $valid; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var int Iteration |
||
| 29 | */ |
||
| 30 | protected $iteration = 0; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param callback $valid Callback for validating next element |
||
| 34 | * @param callback $current Callback for returning current element |
||
| 35 | */ |
||
| 36 | 2 | public function __construct($valid, $current) |
|
| 41 | |||
| 42 | /** |
||
| 43 | * Moves internal pointer to next position. |
||
| 44 | */ |
||
| 45 | 2 | public function next() |
|
| 49 | |||
| 50 | /** |
||
| 51 | * Returns current element. |
||
| 52 | * |
||
| 53 | * @return mixed Current element |
||
| 54 | */ |
||
| 55 | 2 | public function current() |
|
| 59 | |||
| 60 | /** |
||
| 61 | * Returns current position. |
||
| 62 | * |
||
| 63 | * @return int Current position |
||
| 64 | */ |
||
| 65 | 2 | public function key() |
|
| 69 | |||
| 70 | /** |
||
| 71 | * Tests, if next element is valid. |
||
| 72 | * |
||
| 73 | * @return bool True, if valid |
||
| 74 | */ |
||
| 75 | 2 | public function valid() |
|
| 79 | |||
| 80 | /** |
||
| 81 | * Sets internal pointer to initial position. |
||
| 82 | */ |
||
| 83 | 2 | public function rewind() |
|
| 87 | } |
||
| 88 |