| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* League.Csv (https://csv.thephpleague.com) |
| 5 |
* |
| 6 |
* (c) Ignace Nyamagana Butera <[email protected]> |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
|
| 12 |
declare(strict_types=1); |
| 13 |
|
| 14 |
namespace League\Csv; |
| 15 |
|
| 16 |
use IteratorIterator; |
| 17 |
use ReturnTypeWillChange; |
| 18 |
use Traversable; |
| 19 |
|
| 20 |
/** |
| 21 |
* Map value from an iterator before yielding. |
| 22 |
* |
| 23 |
* @internal used internally to modify CSV content |
| 24 |
*/ |
| 25 |
final class MapIterator extends IteratorIterator |
| 26 |
{ |
| 27 |
/** @var callable The callback to apply on all InnerIterator current value. */ |
| 28 |
private $callable; |
| 29 |
|
| 30 |
public function __construct(Traversable $iterator, callable $callable) |
| 31 |
{ |
| 32 |
parent::__construct($iterator); |
| 33 |
$this->callable = $callable; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* @return mixed The value of the current element. |
| 38 |
*/ |
| 39 |
#[ReturnTypeWillChange] |
| 40 |
public function current() |
| 41 |
{ |
| 42 |
return ($this->callable)(parent::current(), parent::key()); |
| 43 |
} |
| 44 |
} |
| 45 |
|