1 | <?php |
||
17 | class RowIterator implements IteratorInterface |
||
18 | { |
||
19 | /** Definition of XML nodes names used to parse data */ |
||
20 | const XML_NODE_TABLE = 'table:table'; |
||
21 | const XML_NODE_ROW = 'table:table-row'; |
||
22 | const XML_NODE_CELL = 'table:table-cell'; |
||
23 | const MAX_COLUMNS_EXCEL = 16384; |
||
24 | |||
25 | /** Definition of XML attribute used to parse data */ |
||
26 | const XML_ATTRIBUTE_NUM_COLUMNS_REPEATED = 'table:number-columns-repeated'; |
||
27 | |||
28 | /** @var \Box\Spout\Reader\Wrapper\XMLReader The XMLReader object that will help read sheet's XML data */ |
||
29 | protected $xmlReader; |
||
30 | |||
31 | /** @var Helper\CellValueFormatter Helper to format cell values */ |
||
32 | protected $cellValueFormatter; |
||
33 | |||
34 | /** @var bool Whether the iterator has already been rewound once */ |
||
35 | protected $hasAlreadyBeenRewound = false; |
||
36 | |||
37 | /** @var int Number of read rows */ |
||
38 | protected $numReadRows = 0; |
||
39 | |||
40 | /** @var array|null Buffer used to store the row data, while checking if there are more rows to read */ |
||
41 | protected $rowDataBuffer = null; |
||
42 | |||
43 | /** @var bool Indicates whether all rows have been read */ |
||
44 | protected $hasReachedEndOfFile = false; |
||
45 | |||
46 | /** |
||
47 | * @param XMLReader $xmlReader XML Reader, positioned on the "<table:table>" element |
||
48 | * @param bool $shouldFormatDates Whether date/time values should be returned as PHP objects or be formatted as strings |
||
49 | */ |
||
50 | public function __construct($xmlReader, $shouldFormatDates) |
||
55 | |||
56 | /** |
||
57 | * Rewind the Iterator to the first element. |
||
58 | * NOTE: It can only be done once, as it is not possible to read an XML file backwards. |
||
59 | * @link http://php.net/manual/en/iterator.rewind.php |
||
60 | * |
||
61 | * @return void |
||
62 | * @throws \Box\Spout\Reader\Exception\IteratorNotRewindableException If the iterator is rewound more than once |
||
63 | */ |
||
64 | public function rewind() |
||
80 | |||
81 | /** |
||
82 | * Checks if current position is valid |
||
83 | * @link http://php.net/manual/en/iterator.valid.php |
||
84 | * |
||
85 | * @return boolean |
||
86 | */ |
||
87 | public function valid() |
||
91 | |||
92 | /** |
||
93 | * Move forward to next element. Empty rows will be skipped. |
||
94 | * @link http://php.net/manual/en/iterator.next.php |
||
95 | * |
||
96 | * @return void |
||
97 | * @throws \Box\Spout\Reader\Exception\SharedStringNotFoundException If a shared string was not found |
||
98 | * @throws \Box\Spout\Common\Exception\IOException If unable to read the sheet data XML |
||
99 | */ |
||
100 | public function next() |
||
166 | |||
167 | /** |
||
168 | * @return int The value of "table:number-columns-repeated" attribute of the current node, or 1 if attribute missing |
||
169 | */ |
||
170 | protected function getNumColumnsRepeatedForCurrentNode() |
||
175 | |||
176 | /** |
||
177 | * Returns the (unescaped) correctly marshalled, cell value associated to the given XML node. |
||
178 | * |
||
179 | * @param \DOMNode $node |
||
180 | * @return string|int|float|bool|\DateTime|\DateInterval|null The value associated with the cell, empty string if cell's type is void/undefined, null on error |
||
181 | */ |
||
182 | protected function getCellValue($node) |
||
186 | |||
187 | /** |
||
188 | * empty() replacement that honours 0 as a valid value |
||
189 | * |
||
190 | * @param string|int|float|bool|\DateTime|\DateInterval|null $value The cell value |
||
191 | * @return bool |
||
192 | */ |
||
193 | protected function isEmptyCellValue($value) |
||
197 | |||
198 | /** |
||
199 | * Return the current element, from the buffer. |
||
200 | * @link http://php.net/manual/en/iterator.current.php |
||
201 | * |
||
202 | * @return array|null |
||
203 | */ |
||
204 | public function current() |
||
208 | |||
209 | /** |
||
210 | * Return the key of the current element |
||
211 | * @link http://php.net/manual/en/iterator.key.php |
||
212 | * |
||
213 | * @return int |
||
214 | */ |
||
215 | public function key() |
||
219 | |||
220 | |||
221 | /** |
||
222 | * Cleans up what was created to iterate over the object. |
||
223 | * |
||
224 | * @return void |
||
225 | */ |
||
226 | public function end() |
||
230 | } |
||
231 |