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