| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\OpenSpout\Reader\ODS; |
| 4 |
|
| 5 |
use FluentCart\OpenSpout\Common\Exception\IOException; |
| 6 |
use FluentCart\OpenSpout\Reader\ODS\Creator\InternalEntityFactory; |
| 7 |
use FluentCart\OpenSpout\Reader\ReaderAbstract; |
| 8 |
/** |
| 9 |
* This class provides support to read data from a ODS file. |
| 10 |
*/ |
| 11 |
class Reader extends ReaderAbstract |
| 12 |
{ |
| 13 |
/** @var \ZipArchive */ |
| 14 |
protected $zip; |
| 15 |
/** @var SheetIterator To iterator over the ODS sheets */ |
| 16 |
protected $sheetIterator; |
| 17 |
/** |
| 18 |
* Returns whether stream wrappers are supported. |
| 19 |
* |
| 20 |
* @return bool |
| 21 |
*/ |
| 22 |
protected function doesSupportStreamWrapper() |
| 23 |
{ |
| 24 |
return \false; |
| 25 |
} |
| 26 |
/** |
| 27 |
* Opens the file at the given file path to make it ready to be read. |
| 28 |
* |
| 29 |
* @param string $filePath Path of the file to be read |
| 30 |
* |
| 31 |
* @throws \OpenSpout\Common\Exception\IOException If the file at the given path or its content cannot be read |
| 32 |
* @throws \OpenSpout\Reader\Exception\NoSheetsFoundException If there are no sheets in the file |
| 33 |
*/ |
| 34 |
protected function openReader($filePath) |
| 35 |
{ |
| 36 |
/** @var InternalEntityFactory $entityFactory */ |
| 37 |
$entityFactory = $this->entityFactory; |
| 38 |
$this->zip = $entityFactory->createZipArchive(); |
| 39 |
if (\true === $this->zip->open($filePath)) { |
| 40 |
/** @var InternalEntityFactory $entityFactory */ |
| 41 |
$entityFactory = $this->entityFactory; |
| 42 |
$this->sheetIterator = $entityFactory->createSheetIterator($filePath, $this->optionsManager); |
| 43 |
} else { |
| 44 |
throw new IOException("Could not open {$filePath} for reading."); |
| 45 |
} |
| 46 |
} |
| 47 |
/** |
| 48 |
* Returns an iterator to iterate over sheets. |
| 49 |
* |
| 50 |
* @return SheetIterator To iterate over sheets |
| 51 |
*/ |
| 52 |
protected function getConcreteSheetIterator() |
| 53 |
{ |
| 54 |
return $this->sheetIterator; |
| 55 |
} |
| 56 |
/** |
| 57 |
* Closes the reader. To be used after reading the file. |
| 58 |
*/ |
| 59 |
protected function closeReader() |
| 60 |
{ |
| 61 |
if (null !== $this->zip) { |
| 62 |
$this->zip->close(); |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
|