32 lines
631 B
PHP
32 lines
631 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
class CsvReader
|
|
{
|
|
private $file;
|
|
// private array $headers;
|
|
|
|
public array $lines = [];
|
|
|
|
public function __construct(
|
|
public string $filename,
|
|
) {
|
|
$this->file = fopen($filename, 'r');
|
|
if (! $this->file) {
|
|
throw new \RuntimeException('Failed to open file: '.$filename);
|
|
}
|
|
|
|
// $this->headers = $this->readNextLine();
|
|
}
|
|
|
|
public function readNextLine(): ?array
|
|
{
|
|
if (($data = fgetcsv($this->file, 1000, ',')) !== false) {
|
|
return $data;
|
|
}
|
|
|
|
return null; // End of file or error
|
|
}
|
|
}
|