31 lines
635 B
PHP
31 lines
635 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
|
|
}
|
|
}
|