1 | <?php |
||
14 | abstract class AbstractReader implements ReaderInterface |
||
15 | { |
||
16 | /** @var bool Indicates whether the stream is currently open */ |
||
17 | protected $isStreamOpened = false; |
||
18 | |||
19 | /** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper Helper to work with global functions */ |
||
20 | protected $globalFunctionsHelper; |
||
21 | |||
22 | /** @var bool Whether date/time values should be returned as PHP objects or be formatted as strings */ |
||
23 | protected $shouldFormatDates = false; |
||
24 | |||
25 | /** @var bool Whether empty rows should be returned or skipped */ |
||
26 | protected $shouldPreserveEmptyRows = false; |
||
27 | |||
28 | /** |
||
29 | * Returns whether stream wrappers are supported |
||
30 | * |
||
31 | * @return bool |
||
32 | */ |
||
33 | abstract protected function doesSupportStreamWrapper(); |
||
34 | |||
35 | /** |
||
36 | * Opens the file at the given file path to make it ready to be read |
||
37 | * |
||
38 | * @param string $filePath Path of the file to be read |
||
39 | * @return void |
||
40 | */ |
||
41 | abstract protected function openReader($filePath); |
||
42 | |||
43 | /** |
||
44 | * Returns an iterator to iterate over sheets. |
||
45 | * |
||
46 | * @return \Iterator To iterate over sheets |
||
47 | */ |
||
48 | abstract public function getConcreteSheetIterator(); |
||
49 | |||
50 | /** |
||
51 | * Closes the reader. To be used after reading the file. |
||
52 | * |
||
53 | * @return AbstractReader |
||
54 | */ |
||
55 | abstract protected function closeReader(); |
||
56 | |||
57 | /** |
||
58 | * @param \Box\Spout\Common\Helper\GlobalFunctionsHelper $globalFunctionsHelper |
||
59 | * @return AbstractReader |
||
60 | */ |
||
61 | 300 | public function setGlobalFunctionsHelper($globalFunctionsHelper) |
|
66 | |||
67 | /** |
||
68 | * Sets whether date/time values should be returned as PHP objects or be formatted as strings. |
||
69 | * |
||
70 | * @api |
||
71 | * @param bool $shouldFormatDates |
||
72 | * @return AbstractReader |
||
73 | */ |
||
74 | 183 | public function setShouldFormatDates($shouldFormatDates) |
|
79 | |||
80 | /** |
||
81 | * Sets whether empty rows should be returned or skipped. |
||
82 | * |
||
83 | * @api |
||
84 | * @param bool $shouldPreserveEmptyRows |
||
85 | * @return AbstractReader |
||
86 | */ |
||
87 | 243 | public function setShouldPreserveEmptyRows($shouldPreserveEmptyRows) |
|
92 | |||
93 | /** |
||
94 | * Prepares the reader to read the given file. It also makes sure |
||
95 | * that the file exists and is readable. |
||
96 | * |
||
97 | * @api |
||
98 | * @param string $filePath Path of the file to be read |
||
99 | * @return void |
||
100 | * @throws \Box\Spout\Common\Exception\IOException If the file at the given path does not exist, is not readable or is corrupted |
||
101 | */ |
||
102 | 297 | public function open($filePath) |
|
125 | |||
126 | /** |
||
127 | * Returns the real path of the given path. |
||
128 | * If the given path is a valid stream wrapper, returns the path unchanged. |
||
129 | * |
||
130 | * @param string $filePath |
||
131 | * @return string |
||
132 | */ |
||
133 | 270 | protected function getFileRealPath($filePath) |
|
142 | |||
143 | /** |
||
144 | * Returns the scheme of the custom stream wrapper, if the path indicates a stream wrapper is used. |
||
145 | * For example, php://temp => php, s3://path/to/file => s3... |
||
146 | * |
||
147 | * @param string $filePath Path of the file to be read |
||
148 | * @return string|null The stream wrapper scheme or NULL if not a stream wrapper |
||
149 | */ |
||
150 | 297 | protected function getStreamWrapperScheme($filePath) |
|
158 | |||
159 | /** |
||
160 | * Checks if the given path is an unsupported stream wrapper |
||
161 | * (like local path, php://temp, mystream://foo/bar...). |
||
162 | * |
||
163 | * @param string $filePath Path of the file to be read |
||
164 | * @return bool Whether the given path is an unsupported stream wrapper |
||
165 | */ |
||
166 | 297 | protected function isStreamWrapper($filePath) |
|
170 | |||
171 | /** |
||
172 | * Checks if the given path is an supported stream wrapper |
||
173 | * (like php://temp, mystream://foo/bar...). |
||
174 | * If the given path is a local path, returns true. |
||
175 | * |
||
176 | * @param string $filePath Path of the file to be read |
||
177 | * @return bool Whether the given path is an supported stream wrapper |
||
178 | */ |
||
179 | 273 | protected function isSupportedStreamWrapper($filePath) |
|
186 | |||
187 | /** |
||
188 | * Checks if a path is a PHP stream (like php://output, php://memory, ...) |
||
189 | * |
||
190 | * @param string $filePath Path of the file to be read |
||
191 | * @return bool Whether the given path maps to a PHP stream |
||
192 | */ |
||
193 | 282 | protected function isPhpStream($filePath) |
|
198 | |||
199 | /** |
||
200 | * Returns an iterator to iterate over sheets. |
||
201 | * |
||
202 | * @api |
||
203 | * @return \Iterator To iterate over sheets |
||
204 | * @throws \Box\Spout\Reader\Exception\ReaderNotOpenedException If called before opening the reader |
||
205 | */ |
||
206 | 258 | public function getSheetIterator() |
|
214 | |||
215 | /** |
||
216 | * Closes the reader, preventing any additional reading |
||
217 | * |
||
218 | * @api |
||
219 | * @return void |
||
220 | */ |
||
221 | 243 | public function close() |
|
234 | } |
||
235 |