| 1 | <?php |
||
| 16 | class MappingIterator extends IteratorIterator { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var callable |
||
| 20 | */ |
||
| 21 | private $callback; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @since 1.0 |
||
| 25 | * |
||
| 26 | * @param Iterator|array $iterator |
||
| 27 | * @param callable $callback |
||
| 28 | */ |
||
| 29 | 4 | public function __construct( $iterator, callable $callback ) { |
|
| 30 | |||
| 31 | 4 | if ( is_array( $iterator ) ) { |
|
| 32 | 2 | $iterator = new ArrayIterator( $iterator ); |
|
| 33 | } |
||
| 34 | |||
| 35 | 4 | if ( !$iterator instanceof Iterator ) { |
|
| 36 | 1 | throw new RuntimeException( "CallbackIterator expected an Iterator" ); |
|
| 37 | } |
||
| 38 | |||
| 39 | 3 | parent::__construct( $iterator ); |
|
| 40 | 3 | $this->callback = $callback; |
|
| 41 | 3 | } |
|
| 42 | |||
| 43 | /** |
||
| 44 | * @since 1.0 |
||
| 45 | * |
||
| 46 | * {@inheritDoc} |
||
| 47 | */ |
||
| 48 | 2 | public function current() { |
|
| 51 | |||
| 52 | } |
||
| 53 |