1 | <?php |
||
14 | class Reader extends AbstractCsv implements \Iterator |
||
15 | { |
||
16 | /** @var string */ |
||
17 | protected $defaultNormalizer = NullNormalizer::class; |
||
18 | /** @var NormalizerInterface */ |
||
19 | protected $headerNormalizer; |
||
20 | /** @var string */ |
||
21 | protected $openMode = 'r'; |
||
22 | /** @var NormalizerInterface[] */ |
||
23 | protected $normalizers = []; |
||
24 | /** @var Row */ |
||
25 | protected $headers; |
||
26 | /** @var Row */ |
||
27 | protected $row; |
||
28 | /** @var bool */ |
||
29 | protected $bom = false; |
||
30 | /** @var int */ |
||
31 | protected $offset = 0; |
||
32 | |||
33 | 8 | public function __construct($file, $hasHeaders = true, $delimiter = ',', $enclosure = '"', $escape = "\0") |
|
38 | |||
39 | /** |
||
40 | * @param string $file |
||
41 | * |
||
42 | * @return Reader |
||
43 | */ |
||
44 | public static function read($file) |
||
50 | |||
51 | /** |
||
52 | * @return Row |
||
53 | */ |
||
54 | 2 | public function getHeaders() |
|
62 | |||
63 | /** |
||
64 | * @param $key |
||
65 | * |
||
66 | * @return mixed |
||
67 | */ |
||
68 | 7 | public function getHeader($key) |
|
76 | |||
77 | /** |
||
78 | * @param NormalizerInterface $headerNormalizer |
||
79 | */ |
||
80 | public function setHeaderNormalizer(NormalizerInterface $headerNormalizer) |
||
86 | |||
87 | /** |
||
88 | * @param mixed $key |
||
89 | * @param NormalizerInterface $normalizer Normalizer instance. |
||
90 | * |
||
91 | * @return $this |
||
92 | */ |
||
93 | public function addNormalizer($key, NormalizerInterface $normalizer) |
||
99 | |||
100 | /** |
||
101 | * @param array|\Traversable $normalizers |
||
102 | * |
||
103 | * @return $this |
||
104 | */ |
||
105 | public function addNormalizers($normalizers) |
||
113 | |||
114 | /** |
||
115 | * @param mixed $key |
||
116 | * |
||
117 | * @return NormalizerInterface |
||
118 | */ |
||
119 | 7 | public function getNormalizer($key) |
|
133 | |||
134 | /** |
||
135 | * Reads the next line in the CSV file |
||
136 | * and returns a Row object from it. |
||
137 | * |
||
138 | * @return Row|null |
||
139 | */ |
||
140 | 4 | protected function getCurrentRow() |
|
160 | |||
161 | /** |
||
162 | * @inheritDoc |
||
163 | */ |
||
164 | 2 | public function current() |
|
168 | |||
169 | /** |
||
170 | * @inheritDoc |
||
171 | */ |
||
172 | 4 | public function next() |
|
176 | |||
177 | /** |
||
178 | * @inheritDoc |
||
179 | */ |
||
180 | 4 | public function key() |
|
184 | |||
185 | /** |
||
186 | * @inheritDoc |
||
187 | */ |
||
188 | 2 | public function valid() |
|
194 | |||
195 | /** |
||
196 | * @inheritDoc |
||
197 | */ |
||
198 | 4 | public function rewind() |
|
211 | |||
212 | /** |
||
213 | * @param string $defaultNormalizer |
||
214 | * |
||
215 | * @return Reader |
||
216 | */ |
||
217 | public function setDefaultNormalizer($defaultNormalizer) |
||
223 | |||
224 | /** |
||
225 | * @return string |
||
226 | */ |
||
227 | 5 | public function getDefaultNormalizer() |
|
231 | |||
232 | /** |
||
233 | * @param bool $bom |
||
234 | * |
||
235 | * @return Reader |
||
236 | */ |
||
237 | 2 | public function setBom($bom) |
|
243 | |||
244 | /** |
||
245 | * @return bool |
||
246 | */ |
||
247 | 3 | public function hasBom() |
|
251 | |||
252 | /** |
||
253 | * @param int $offset |
||
254 | */ |
||
255 | 1 | public function setOffset($offset) |
|
259 | |||
260 | /** |
||
261 | * @return int |
||
262 | */ |
||
263 | public function getOffset() |
||
267 | |||
268 | /** |
||
269 | * @return array |
||
270 | */ |
||
271 | public function toArray() |
||
280 | } |
||
281 |