Files
core/src/MigrateImport/JudgeMe/Services/JudgeMeCsvReader.php
T

32 lines
627 B
PHP

<?php
namespace Modules\Core\MigrateImport\JudgeMe\Services;
use RuntimeException;
class JudgeMeCsvReader
{
/**
* @return array<int, array<string, string>>
*/
public function read(string $csvPath): array
{
$handle = fopen($csvPath, 'r');
if ($handle === false) {
throw new RuntimeException("Could not open CSV file: {$csvPath}");
}
$headers = fgetcsv($handle);
$rows = [];
while (($row = fgetcsv($handle)) !== false) {
$rows[] = array_combine($headers, $row);
}
fclose($handle);
return $rows;
}
}