1 | <?php |
||
18 | abstract class ReaderAbstract implements ReaderInterface |
||
19 | { |
||
20 | /** @var bool Indicates whether the stream is currently open */ |
||
21 | protected $isStreamOpened = false; |
||
22 | |||
23 | /** @var EntityFactoryInterface Factory to create entities */ |
||
24 | protected $entityFactory; |
||
25 | |||
26 | /** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper Helper to work with global functions */ |
||
27 | protected $globalFunctionsHelper; |
||
28 | |||
29 | /** @var OptionsManagerInterface Writer options manager */ |
||
30 | protected $optionsManager; |
||
31 | |||
32 | /** |
||
33 | * Returns whether stream wrappers are supported |
||
34 | * |
||
35 | * @return bool |
||
36 | */ |
||
37 | abstract protected function doesSupportStreamWrapper(); |
||
38 | |||
39 | /** |
||
40 | * Opens the file at the given file path to make it ready to be read |
||
41 | * |
||
42 | * @param string $filePath Path of the file to be read |
||
43 | * @return void |
||
44 | */ |
||
45 | abstract protected function openReader($filePath); |
||
46 | |||
47 | /** |
||
48 | * Returns an iterator to iterate over sheets. |
||
49 | * |
||
50 | * @return IteratorInterface To iterate over sheets |
||
51 | */ |
||
52 | abstract protected function getConcreteSheetIterator(); |
||
53 | |||
54 | /** |
||
55 | * Closes the reader. To be used after reading the file. |
||
56 | * |
||
57 | * @return ReaderAbstract |
||
58 | */ |
||
59 | abstract protected function closeReader(); |
||
60 | |||
61 | /** |
||
62 | * @param OptionsManagerInterface $optionsManager |
||
63 | * @param GlobalFunctionsHelper $globalFunctionsHelper |
||
64 | * @param EntityFactoryInterface $entityFactory |
||
65 | */ |
||
66 | 103 | public function __construct( |
|
75 | |||
76 | /** |
||
77 | * Sets whether date/time values should be returned as PHP objects or be formatted as strings. |
||
78 | * |
||
79 | * @api |
||
80 | * @param bool $shouldFormatDates |
||
81 | * @return ReaderAbstract |
||
82 | */ |
||
83 | 62 | public function setShouldFormatDates($shouldFormatDates) |
|
88 | |||
89 | /** |
||
90 | * Sets whether empty rows should be returned or skipped. |
||
91 | * |
||
92 | * @api |
||
93 | * @param bool $shouldPreserveEmptyRows |
||
94 | * @return ReaderAbstract |
||
95 | */ |
||
96 | 81 | public function setShouldPreserveEmptyRows($shouldPreserveEmptyRows) |
|
101 | |||
102 | /** |
||
103 | * Prepares the reader to read the given file. It also makes sure |
||
104 | * that the file exists and is readable. |
||
105 | * |
||
106 | * @api |
||
107 | * @param string $filePath Path of the file to be read |
||
108 | * @return void |
||
109 | * @throws \Box\Spout\Common\Exception\IOException If the file at the given path does not exist, is not readable or is corrupted |
||
110 | */ |
||
111 | 102 | public function open($filePath) |
|
134 | |||
135 | /** |
||
136 | * Returns the real path of the given path. |
||
137 | * If the given path is a valid stream wrapper, returns the path unchanged. |
||
138 | * |
||
139 | * @param string $filePath |
||
140 | * @return string |
||
141 | */ |
||
142 | 93 | protected function getFileRealPath($filePath) |
|
151 | |||
152 | /** |
||
153 | * Returns the scheme of the custom stream wrapper, if the path indicates a stream wrapper is used. |
||
154 | * For example, php://temp => php, s3://path/to/file => s3... |
||
155 | * |
||
156 | * @param string $filePath Path of the file to be read |
||
157 | * @return string|null The stream wrapper scheme or NULL if not a stream wrapper |
||
158 | */ |
||
159 | 102 | protected function getStreamWrapperScheme($filePath) |
|
167 | |||
168 | /** |
||
169 | * Checks if the given path is an unsupported stream wrapper |
||
170 | * (like local path, php://temp, mystream://foo/bar...). |
||
171 | * |
||
172 | * @param string $filePath Path of the file to be read |
||
173 | * @return bool Whether the given path is an unsupported stream wrapper |
||
174 | */ |
||
175 | 102 | protected function isStreamWrapper($filePath) |
|
179 | |||
180 | /** |
||
181 | * Checks if the given path is an supported stream wrapper |
||
182 | * (like php://temp, mystream://foo/bar...). |
||
183 | * If the given path is a local path, returns true. |
||
184 | * |
||
185 | * @param string $filePath Path of the file to be read |
||
186 | * @return bool Whether the given path is an supported stream wrapper |
||
187 | */ |
||
188 | 94 | protected function isSupportedStreamWrapper($filePath) |
|
195 | |||
196 | /** |
||
197 | * Checks if a path is a PHP stream (like php://output, php://memory, ...) |
||
198 | * |
||
199 | * @param string $filePath Path of the file to be read |
||
200 | * @return bool Whether the given path maps to a PHP stream |
||
201 | */ |
||
202 | 97 | protected function isPhpStream($filePath) |
|
207 | |||
208 | /** |
||
209 | * Returns an iterator to iterate over sheets. |
||
210 | * |
||
211 | * @api |
||
212 | * @return \Iterator To iterate over sheets |
||
213 | * @throws \Box\Spout\Reader\Exception\ReaderNotOpenedException If called before opening the reader |
||
214 | */ |
||
215 | 90 | public function getSheetIterator() |
|
223 | |||
224 | /** |
||
225 | * Closes the reader, preventing any additional reading |
||
226 | * |
||
227 | * @api |
||
228 | * @return void |
||
229 | */ |
||
230 | 85 | public function close() |
|
243 | } |
||
244 |