File: CsvLineGenerator.php Lines 3 to 22 |
|
3 | |
|
4 | class CsvLineGenerator |
|
5 | { |
|
6 | /** |
|
7 | * CSVを1行ずつ返すgenerator |
|
8 | * @param string $fullpath |
|
9 | * @return \Generator |
|
10 | */ |
|
11 | public static function eachLine($fullpath) { |
| | $fp = @fopen($fullpath, 'rb'); |
|
13 | if($fp === false) { |
|
14 | throw new \RuntimeException("cannot open stream: $fullpath"); |
|
15 | } |
|
16 | try { |
|
17 | while (false !== $line = fgetcsv($fp)) { |
|
18 | yield $line; |
|
19 | } |
|
20 | } finally { |
|
21 | fclose($fp); |
|
22 | } |
|