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