1 | <?php |
||
10 | class Reader implements \Iterator |
||
11 | { |
||
12 | /** |
||
13 | * The column headers. |
||
14 | * |
||
15 | * @var array |
||
16 | */ |
||
17 | private $headers; |
||
18 | |||
19 | /** |
||
20 | * The current file pointer position. |
||
21 | * |
||
22 | * @var integer |
||
23 | */ |
||
24 | private $position = 0; |
||
25 | |||
26 | /** |
||
27 | * The current row within the csv file. |
||
28 | * |
||
29 | * @var array|false|null |
||
30 | */ |
||
31 | private $current = null; |
||
32 | |||
33 | /** |
||
34 | * @var SplFileObject |
||
35 | */ |
||
36 | private $fileObject; |
||
37 | |||
38 | /** |
||
39 | * Create a new Reader instance. |
||
40 | * |
||
41 | * @param string $file The full path to the csv file. |
||
42 | * @param HeaderStrategyInterface $headerStrategy Strategy for obtaining headers of the file. |
||
43 | * @param CsvOptions $csvOptions Options for the csv file. |
||
44 | * |
||
45 | * @throws \InvalidArgumentException Thrown if $file is not readable. |
||
46 | */ |
||
47 | public function __construct($file, HeaderStrategyInterface $headerStrategy = null, CsvOptions $csvOptions = null) |
||
68 | |||
69 | /** |
||
70 | * Advances to the next row in this csv reader |
||
71 | * |
||
72 | * @return mixed |
||
73 | */ |
||
74 | public function next() |
||
94 | |||
95 | /** |
||
96 | * Helper method to read the next line in the delimited file. |
||
97 | * |
||
98 | * @return array|false |
||
99 | * |
||
100 | * @throws \Exception Thrown if no data is returned when reading the file. |
||
101 | */ |
||
102 | private function readLine() |
||
111 | |||
112 | /** |
||
113 | * Return the current element. |
||
114 | * |
||
115 | * @return array returns array containing values from the current row |
||
116 | */ |
||
117 | public function current() |
||
125 | |||
126 | /** |
||
127 | * Return the key of the current element. |
||
128 | * |
||
129 | * @return integer |
||
130 | */ |
||
131 | public function key() |
||
135 | |||
136 | /** |
||
137 | * Rewind the Iterator to the first element. |
||
138 | * |
||
139 | * @return void |
||
140 | */ |
||
141 | public function rewind() |
||
147 | |||
148 | /** |
||
149 | * Check if there is a current element after calls to rewind() or next(). |
||
150 | * |
||
151 | * @return bool true if there is a current element, false otherwise |
||
152 | */ |
||
153 | public function valid() |
||
161 | |||
162 | /** |
||
163 | * Ensure file handles are closed when all references to this reader are destroyed. |
||
164 | * |
||
165 | * @return void |
||
166 | */ |
||
167 | public function __destruct() |
||
171 | } |
||
172 |