1 | <?php |
||
25 | class CsvParser implements ParserInterface |
||
26 | { |
||
27 | /** @var CsvFormatInterface */ |
||
28 | private $csvFormat; |
||
29 | /** @var array */ |
||
30 | private $headerRow = []; |
||
31 | |||
32 | /** |
||
33 | * @param CsvFormatInterface $csvFormat |
||
34 | */ |
||
35 | 13 | public function __construct(CsvFormatInterface $csvFormat) |
|
39 | |||
40 | /** |
||
41 | * @param resource $stream |
||
42 | * |
||
43 | * @return Iterator |
||
44 | */ |
||
45 | 12 | public function parse($stream) |
|
53 | |||
54 | /** |
||
55 | * Parse a supplied iterator |
||
56 | * |
||
57 | * @param Iterator $iterator |
||
58 | * |
||
59 | * @return Iterator |
||
60 | */ |
||
61 | 12 | private function parseIterator(Iterator $iterator) |
|
73 | |||
74 | /** |
||
75 | * @param Iterator $iterator |
||
76 | * |
||
77 | * @return Iterator |
||
78 | */ |
||
79 | 12 | private function parseHeaderRow(Iterator $iterator) |
|
87 | |||
88 | /** |
||
89 | * Parse the rows looking for the header row and storing it locally |
||
90 | * |
||
91 | * @param array $current |
||
92 | * @param int $key |
||
93 | * |
||
94 | * @return bool |
||
95 | */ |
||
96 | 4 | public function handleHeaderRow(array $current, $key) |
|
105 | |||
106 | /** |
||
107 | * Map any headers found onto each element in the data |
||
108 | * |
||
109 | * @param array $current |
||
110 | * |
||
111 | * @return array |
||
112 | */ |
||
113 | 4 | public function mapHeaders(array $current) |
|
129 | } |
||
130 |