| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\OpenSpout\Reader\CSV; |
| 4 |
|
| 5 |
use FluentCart\OpenSpout\Reader\SheetIteratorInterface; |
| 6 |
/** |
| 7 |
* Iterate over CSV unique "sheet". |
| 8 |
*/ |
| 9 |
class SheetIterator implements SheetIteratorInterface |
| 10 |
{ |
| 11 |
/** @var Sheet The CSV unique "sheet" */ |
| 12 |
protected $sheet; |
| 13 |
/** @var bool Whether the unique "sheet" has already been read */ |
| 14 |
protected $hasReadUniqueSheet = \false; |
| 15 |
/** |
| 16 |
* @param Sheet $sheet Corresponding unique sheet |
| 17 |
*/ |
| 18 |
public function __construct($sheet) |
| 19 |
{ |
| 20 |
$this->sheet = $sheet; |
| 21 |
} |
| 22 |
/** |
| 23 |
* Rewind the Iterator to the first element. |
| 24 |
* |
| 25 |
* @see http://php.net/manual/en/iterator.rewind.php |
| 26 |
*/ |
| 27 |
#[\ReturnTypeWillChange] |
| 28 |
public function rewind() : void |
| 29 |
{ |
| 30 |
$this->hasReadUniqueSheet = \false; |
| 31 |
} |
| 32 |
/** |
| 33 |
* Checks if current position is valid. |
| 34 |
* |
| 35 |
* @see http://php.net/manual/en/iterator.valid.php |
| 36 |
*/ |
| 37 |
#[\ReturnTypeWillChange] |
| 38 |
public function valid() : bool |
| 39 |
{ |
| 40 |
return !$this->hasReadUniqueSheet; |
| 41 |
} |
| 42 |
/** |
| 43 |
* Move forward to next element. |
| 44 |
* |
| 45 |
* @see http://php.net/manual/en/iterator.next.php |
| 46 |
*/ |
| 47 |
#[\ReturnTypeWillChange] |
| 48 |
public function next() : void |
| 49 |
{ |
| 50 |
$this->hasReadUniqueSheet = \true; |
| 51 |
} |
| 52 |
/** |
| 53 |
* Return the current element. |
| 54 |
* |
| 55 |
* @see http://php.net/manual/en/iterator.current.php |
| 56 |
*/ |
| 57 |
#[\ReturnTypeWillChange] |
| 58 |
public function current() : Sheet |
| 59 |
{ |
| 60 |
return $this->sheet; |
| 61 |
} |
| 62 |
/** |
| 63 |
* Return the key of the current element. |
| 64 |
* |
| 65 |
* @see http://php.net/manual/en/iterator.key.php |
| 66 |
*/ |
| 67 |
#[\ReturnTypeWillChange] |
| 68 |
public function key() : int |
| 69 |
{ |
| 70 |
return 1; |
| 71 |
} |
| 72 |
/** |
| 73 |
* Cleans up what was created to iterate over the object. |
| 74 |
*/ |
| 75 |
#[\ReturnTypeWillChange] |
| 76 |
public function end() : void |
| 77 |
{ |
| 78 |
// do nothing |
| 79 |
} |
| 80 |
} |
| 81 |
|