| 1 |
<?php |
| 2 |
/** |
| 3 |
* This file is part of the League.csv library |
| 4 |
* |
| 5 |
* @license http://opensource.org/licenses/MIT |
| 6 |
* @link https://github.com/thephpleague/csv/ |
| 7 |
* @version 8.2.2 |
| 8 |
* @package League.csv |
| 9 |
* |
| 10 |
* For the full copyright and license information, please view the LICENSE |
| 11 |
* file that was distributed with this source code. |
| 12 |
*/ |
| 13 |
namespace League\Csv\Modifier; |
| 14 |
|
| 15 |
use Iterator; |
| 16 |
use IteratorIterator; |
| 17 |
|
| 18 |
/** |
| 19 |
* A simple MapIterator |
| 20 |
* |
| 21 |
* @package League.csv |
| 22 |
* @since 3.3.0 |
| 23 |
* @internal used internally to modify CSV content |
| 24 |
* |
| 25 |
*/ |
| 26 |
class MapIterator extends IteratorIterator |
| 27 |
{ |
| 28 |
/** |
| 29 |
* The function to be apply on all InnerIterator element |
| 30 |
* |
| 31 |
* @var callable |
| 32 |
*/ |
| 33 |
private $callable; |
| 34 |
|
| 35 |
/** |
| 36 |
* The Constructor |
| 37 |
* |
| 38 |
* @param Iterator $iterator |
| 39 |
* @param callable $callable |
| 40 |
*/ |
| 41 |
public function __construct(Iterator $iterator, callable $callable) |
| 42 |
{ |
| 43 |
parent::__construct($iterator); |
| 44 |
$this->callable = $callable; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Get the value of the current element |
| 49 |
*/ |
| 50 |
public function current() |
| 51 |
{ |
| 52 |
$iterator = $this->getInnerIterator(); |
| 53 |
|
| 54 |
return call_user_func($this->callable, $iterator->current(), $iterator->key(), $iterator); |
| 55 |
} |
| 56 |
} |
| 57 |
|