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