1 | <?php |
||
17 | abstract class ReaderAbstract implements ReaderInterface |
||
18 | { |
||
19 | /** @var bool Indicates whether the stream is currently open */ |
||
20 | protected $isStreamOpened = false; |
||
21 | |||
22 | /** @var InternalEntityFactoryInterface Factory to create entities */ |
||
23 | protected $entityFactory; |
||
24 | |||
25 | /** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper Helper to work with global functions */ |
||
26 | protected $globalFunctionsHelper; |
||
27 | |||
28 | /** @var OptionsManagerInterface Writer options manager */ |
||
29 | protected $optionsManager; |
||
30 | |||
31 | /** @var int The column index where the reader should start */ |
||
32 | protected $startColumnIndex; |
||
33 | |||
34 | /** @var int The column index where the reader should stop */ |
||
35 | protected $endColumnIndex; |
||
36 | |||
37 | /** |
||
38 | * Returns whether stream wrappers are supported |
||
39 | * |
||
40 | * @return bool |
||
41 | */ |
||
42 | abstract protected function doesSupportStreamWrapper(); |
||
43 | |||
44 | /** |
||
45 | * Opens the file at the given file path to make it ready to be read |
||
46 | * |
||
47 | * @param string $filePath Path of the file to be read |
||
48 | * @return void |
||
49 | */ |
||
50 | abstract protected function openReader($filePath); |
||
51 | |||
52 | /** |
||
53 | * Returns an iterator to iterate over sheets. |
||
54 | * |
||
55 | * @return IteratorInterface To iterate over sheets |
||
56 | */ |
||
57 | abstract protected function getConcreteSheetIterator(); |
||
58 | |||
59 | /** |
||
60 | * Closes the reader. To be used after reading the file. |
||
61 | * |
||
62 | * @return ReaderAbstract |
||
63 | */ |
||
64 | abstract protected function closeReader(); |
||
65 | |||
66 | /** |
||
67 | * @param OptionsManagerInterface $optionsManager |
||
68 | * @param GlobalFunctionsHelper $globalFunctionsHelper |
||
69 | * @param InternalEntityFactoryInterface $entityFactory |
||
70 | */ |
||
71 | 115 | public function __construct( |
|
80 | |||
81 | /** |
||
82 | * Sets whether date/time values should be returned as PHP objects or be formatted as strings. |
||
83 | * |
||
84 | * @param bool $shouldFormatDates |
||
85 | * @return ReaderAbstract |
||
86 | */ |
||
87 | 66 | public function setShouldFormatDates($shouldFormatDates) |
|
93 | |||
94 | /** |
||
95 | * Sets whether empty rows should be returned or skipped. |
||
96 | * |
||
97 | * @param bool $shouldPreserveEmptyRows |
||
98 | * @return ReaderAbstract |
||
99 | */ |
||
100 | 90 | public function setShouldPreserveEmptyRows($shouldPreserveEmptyRows) |
|
106 | |||
107 | /** |
||
108 | * @param int $startColumnIndex The 0 based start column index |
||
109 | * @return ReaderAbstract |
||
110 | */ |
||
111 | 25 | public function setStartColumnIndex(int $startColumnIndex) : ReaderAbstract |
|
117 | |||
118 | /** |
||
119 | * @param int $endColumnIndex |
||
120 | * @return ReaderAbstract |
||
121 | */ |
||
122 | 4 | public function setEndColumnIndex(int $endColumnIndex) : ReaderAbstract |
|
128 | |||
129 | /** |
||
130 | * Prepares the reader to read the given file. It also makes sure |
||
131 | * that the file exists and is readable. |
||
132 | * |
||
133 | * @param string $filePath Path of the file to be read |
||
134 | * @throws \Box\Spout\Common\Exception\IOException If the file at the given path does not exist, is not readable or is corrupted |
||
135 | * @return void |
||
136 | */ |
||
137 | 114 | public function open($filePath) |
|
161 | |||
162 | /** |
||
163 | * Returns the real path of the given path. |
||
164 | * If the given path is a valid stream wrapper, returns the path unchanged. |
||
165 | * |
||
166 | * @param string $filePath |
||
167 | * @return string |
||
168 | */ |
||
169 | 105 | protected function getFileRealPath($filePath) |
|
178 | |||
179 | /** |
||
180 | * Returns the scheme of the custom stream wrapper, if the path indicates a stream wrapper is used. |
||
181 | * For example, php://temp => php, s3://path/to/file => s3... |
||
182 | * |
||
183 | * @param string $filePath Path of the file to be read |
||
184 | * @return string|null The stream wrapper scheme or NULL if not a stream wrapper |
||
185 | */ |
||
186 | 114 | protected function getStreamWrapperScheme($filePath) |
|
195 | |||
196 | /** |
||
197 | * Checks if the given path is an unsupported stream wrapper |
||
198 | * (like local path, php://temp, mystream://foo/bar...). |
||
199 | * |
||
200 | * @param string $filePath Path of the file to be read |
||
201 | * @return bool Whether the given path is an unsupported stream wrapper |
||
202 | */ |
||
203 | 114 | protected function isStreamWrapper($filePath) |
|
207 | |||
208 | /** |
||
209 | * Checks if the given path is an supported stream wrapper |
||
210 | * (like php://temp, mystream://foo/bar...). |
||
211 | * If the given path is a local path, returns true. |
||
212 | * |
||
213 | * @param string $filePath Path of the file to be read |
||
214 | * @return bool Whether the given path is an supported stream wrapper |
||
215 | */ |
||
216 | 106 | protected function isSupportedStreamWrapper($filePath) |
|
224 | |||
225 | /** |
||
226 | * Checks if a path is a PHP stream (like php://output, php://memory, ...) |
||
227 | * |
||
228 | * @param string $filePath Path of the file to be read |
||
229 | * @return bool Whether the given path maps to a PHP stream |
||
230 | */ |
||
231 | 109 | protected function isPhpStream($filePath) |
|
237 | |||
238 | /** |
||
239 | * Returns an iterator to iterate over sheets. |
||
240 | * |
||
241 | * @throws \Box\Spout\Reader\Exception\ReaderNotOpenedException If called before opening the reader |
||
242 | * @return \Iterator To iterate over sheets |
||
243 | */ |
||
244 | 102 | public function getSheetIterator() |
|
252 | |||
253 | /** |
||
254 | * Closes the reader, preventing any additional reading |
||
255 | * |
||
256 | * @return void |
||
257 | */ |
||
258 | 95 | public function close() |
|
271 | } |
||
272 |