1 | <?php |
||
30 | abstract class AbstractCsv |
||
31 | { |
||
32 | use ValidatorTrait; |
||
33 | |||
34 | /** |
||
35 | * The CSV document |
||
36 | * |
||
37 | * @var StreamIterator|SplFileObject |
||
38 | */ |
||
39 | protected $document; |
||
40 | |||
41 | /** |
||
42 | * the field delimiter (one character only) |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $delimiter = ','; |
||
47 | |||
48 | /** |
||
49 | * the field enclosure character (one character only) |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $enclosure = '"'; |
||
54 | |||
55 | /** |
||
56 | * the field escape character (one character only) |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | protected $escape = '\\'; |
||
61 | |||
62 | /** |
||
63 | * The CSV document BOM sequence |
||
64 | * |
||
65 | * @var string|null |
||
66 | */ |
||
67 | protected $input_bom = null; |
||
68 | |||
69 | /** |
||
70 | * The Output file BOM character |
||
71 | * |
||
72 | * @var string |
||
73 | */ |
||
74 | protected $output_bom = ''; |
||
75 | |||
76 | /** |
||
77 | * collection of stream filters |
||
78 | * |
||
79 | * @var array |
||
80 | */ |
||
81 | protected $stream_filters = []; |
||
82 | |||
83 | /** |
||
84 | * The stream filter mode (read or write) |
||
85 | * |
||
86 | * @var int |
||
87 | */ |
||
88 | protected $stream_filter_mode; |
||
89 | |||
90 | /** |
||
91 | * New instance |
||
92 | * |
||
93 | * @param SplFileObject|StreamIterator $document The CSV Object instance |
||
94 | */ |
||
95 | 210 | protected function __construct($document) |
|
99 | |||
100 | /** |
||
101 | * @inheritdoc |
||
102 | */ |
||
103 | 2 | public function __clone() |
|
107 | |||
108 | /** |
||
109 | * Return a new {@link AbstractCsv} from a SplFileObject |
||
110 | * |
||
111 | * @param SplFileObject $file |
||
112 | * |
||
113 | * @return static |
||
114 | */ |
||
115 | 200 | public static function createFromFileObject(SplFileObject $file): self |
|
127 | |||
128 | /** |
||
129 | * Return a new {@link AbstractCsv} from a PHP resource stream |
||
130 | * |
||
131 | * @param resource $stream |
||
132 | * |
||
133 | * @return static |
||
134 | */ |
||
135 | 12 | public static function createFromStream($stream): self |
|
139 | |||
140 | /** |
||
141 | * Return a new {@link AbstractCsv} from a string |
||
142 | * |
||
143 | * @param string $str the string |
||
144 | * |
||
145 | * @return static |
||
146 | */ |
||
147 | 16 | public static function createFromString(string $str): self |
|
154 | |||
155 | /** |
||
156 | * Return a new {@link AbstractCsv} from a file path |
||
157 | * |
||
158 | * @param string $path file path |
||
159 | * @param string $open_mode the file open mode flag |
||
160 | * |
||
161 | * @return static |
||
162 | */ |
||
163 | 18 | public static function createFromPath(string $path, string $open_mode = 'r+'): self |
|
171 | |||
172 | /** |
||
173 | * Returns the current field delimiter |
||
174 | * |
||
175 | * @return string |
||
176 | */ |
||
177 | 4 | public function getDelimiter(): string |
|
181 | |||
182 | /** |
||
183 | * Returns the current field enclosure |
||
184 | * |
||
185 | * @return string |
||
186 | */ |
||
187 | 4 | public function getEnclosure(): string |
|
191 | |||
192 | /** |
||
193 | * Returns the current field escape character |
||
194 | * |
||
195 | * @return string |
||
196 | */ |
||
197 | 4 | public function getEscape(): string |
|
201 | |||
202 | /** |
||
203 | * Returns the BOM sequence in use on Output methods |
||
204 | * |
||
205 | * @return string |
||
206 | */ |
||
207 | 2 | public function getOutputBOM(): string |
|
211 | |||
212 | /** |
||
213 | * Returns the BOM sequence of the given CSV |
||
214 | * |
||
215 | * @return string |
||
216 | */ |
||
217 | 152 | public function getInputBOM(): string |
|
227 | |||
228 | /** |
||
229 | * Tells whether the stream filter capabilities can be used |
||
230 | * |
||
231 | * @return bool |
||
232 | */ |
||
233 | 4 | public function supportsStreamFilter(): bool |
|
237 | |||
238 | /** |
||
239 | * Tell whether the specify stream filter is attach to the current stream |
||
240 | * |
||
241 | * @return bool |
||
242 | */ |
||
243 | 4 | public function hasStreamFilter(string $filtername): bool |
|
247 | |||
248 | /** |
||
249 | * Retrieves the CSV content |
||
250 | * |
||
251 | * @return string |
||
252 | */ |
||
253 | 32 | public function __toString(): string |
|
260 | |||
261 | /** |
||
262 | * Outputs all data on the CSV file |
||
263 | * |
||
264 | * @param string $filename CSV downloaded name if present adds extra headers |
||
265 | * |
||
266 | * @return int Returns the number of characters read from the handle |
||
267 | * and passed through to the output. |
||
268 | */ |
||
269 | 4 | public function output(string $filename = null): int |
|
280 | |||
281 | /** |
||
282 | * Outputs all data from the CSV |
||
283 | * |
||
284 | * @return int Returns the number of characters read from the handle |
||
285 | * and passed through to the output. |
||
286 | */ |
||
287 | 36 | protected function fpassthru(): int |
|
300 | |||
301 | /** |
||
302 | * Sets the field delimiter |
||
303 | * |
||
304 | * @param string $delimiter |
||
305 | * |
||
306 | * @return static |
||
307 | */ |
||
308 | 2 | public function setDelimiter(string $delimiter): self |
|
318 | |||
319 | /** |
||
320 | * Reset dynamic CSV document properties to improve performance |
||
321 | */ |
||
322 | 4 | protected function resetProperties() |
|
325 | |||
326 | /** |
||
327 | * Sets the field enclosure |
||
328 | * |
||
329 | * @param string $enclosure |
||
330 | * |
||
331 | * @return static |
||
332 | */ |
||
333 | 2 | public function setEnclosure(string $enclosure): self |
|
343 | |||
344 | /** |
||
345 | * Sets the field escape character |
||
346 | * |
||
347 | * @param string $escape |
||
348 | * |
||
349 | * @return static |
||
350 | */ |
||
351 | 2 | public function setEscape(string $escape): self |
|
362 | |||
363 | /** |
||
364 | * Sets the BOM sequence to prepend the CSV on output |
||
365 | * |
||
366 | * @param string $str The BOM sequence |
||
367 | * |
||
368 | * @return static |
||
369 | */ |
||
370 | 6 | public function setOutputBOM(string $str): self |
|
376 | |||
377 | /** |
||
378 | * append a stream filter |
||
379 | * |
||
380 | * @param string $filtername a string or an object that implements the '__toString' method |
||
381 | * |
||
382 | * @throws LogicException If the stream filter API can not be used |
||
383 | * |
||
384 | * @return static |
||
385 | */ |
||
386 | 12 | public function addStreamFilter(string $filtername): self |
|
398 | |||
399 | /** |
||
400 | * The destructor |
||
401 | */ |
||
402 | 210 | public function __destruct() |
|
414 | } |
||
415 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: