PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.21
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.21
1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 All 49 releases
fluent-cart / vendor / openspout / openspout / src / Reader / XLSX / SheetIterator.php

SheetIterator.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.21, at vendor/openspout/openspout/src/Reader/XLSX/SheetIterator.php

103 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\OpenSpout\Reader\XLSX;
4
5 use FluentCart\OpenSpout\Reader\Exception\NoSheetsFoundException;
6 use FluentCart\OpenSpout\Reader\IteratorInterface;
7 use FluentCart\OpenSpout\Reader\XLSX\Manager\SheetManager;
8 /**
9 * Iterate over XLSX sheet.
10 */
11 class SheetIterator implements IteratorInterface
12 {
13 /** @var \OpenSpout\Reader\XLSX\Sheet[] The list of sheet present in the file */
14 protected $sheets;
15 /** @var int The index of the sheet being read (zero-based) */
16 protected $currentSheetIndex;
17 /**
18 * @param SheetManager $sheetManager Manages sheets
19 *
20 * @throws \OpenSpout\Reader\Exception\NoSheetsFoundException If there are no sheets in the file
21 */
22 public function __construct($sheetManager)
23 {
24 // Fetch all available sheets
25 $this->sheets = $sheetManager->getSheets();
26 if (0 === \count($this->sheets)) {
27 throw new NoSheetsFoundException('The file must contain at least one sheet.');
28 }
29 }
30 /**
31 * Rewind the Iterator to the first element.
32 *
33 * @see http://php.net/manual/en/iterator.rewind.php
34 */
35 #[\ReturnTypeWillChange]
36 public function rewind()
37 {
38 $this->currentSheetIndex = 0;
39 }
40 /**
41 * Checks if current position is valid.
42 *
43 * @see http://php.net/manual/en/iterator.valid.php
44 *
45 * @return bool
46 */
47 #[\ReturnTypeWillChange]
48 public function valid()
49 {
50 return $this->currentSheetIndex < \count($this->sheets);
51 }
52 /**
53 * Move forward to next element.
54 *
55 * @see http://php.net/manual/en/iterator.next.php
56 */
57 #[\ReturnTypeWillChange]
58 public function next()
59 {
60 // Using isset here because it is way faster than array_key_exists...
61 if (isset($this->sheets[$this->currentSheetIndex])) {
62 $currentSheet = $this->sheets[$this->currentSheetIndex];
63 $currentSheet->getRowIterator()->end();
64 ++$this->currentSheetIndex;
65 }
66 }
67 /**
68 * Return the current element.
69 *
70 * @see http://php.net/manual/en/iterator.current.php
71 *
72 * @return \OpenSpout\Reader\XLSX\Sheet
73 */
74 #[\ReturnTypeWillChange]
75 public function current()
76 {
77 return $this->sheets[$this->currentSheetIndex];
78 }
79 /**
80 * Return the key of the current element.
81 *
82 * @see http://php.net/manual/en/iterator.key.php
83 *
84 * @return int
85 */
86 #[\ReturnTypeWillChange]
87 public function key()
88 {
89 return $this->currentSheetIndex + 1;
90 }
91 /**
92 * Cleans up what was created to iterate over the object.
93 */
94 #[\ReturnTypeWillChange]
95 public function end()
96 {
97 // make sure we are not leaking memory in case the iteration stopped before the end
98 foreach ($this->sheets as $sheet) {
99 $sheet->getRowIterator()->end();
100 }
101 }
102 }
103