33 lines
755 B
PHP
33 lines
755 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Services;
|
||
|
|
||
|
use League\Csv\Reader;
|
||
|
use Iterator;
|
||
|
|
||
|
class CsvService
|
||
|
{
|
||
|
private const BARRIOS = 'csv/barrios.csv';
|
||
|
private const PRODUCTOS = 'csv/productos.csv';
|
||
|
|
||
|
public static function reader(String $path) : Reader {
|
||
|
$csv = Reader::createFromPath(resource_path($path), 'r');
|
||
|
$csv->setDelimiter("|");
|
||
|
$csv->setEnclosure("'");
|
||
|
$csv->setHeaderOffset(0);
|
||
|
return $csv;
|
||
|
}
|
||
|
|
||
|
public static function getBarrios() : Iterator {
|
||
|
$csv = CsvService::reader(CsvService::BARRIOS);
|
||
|
return $csv->getRecords();
|
||
|
}
|
||
|
|
||
|
public static function getProductos() : Iterator {
|
||
|
$csv = CsvService::reader(CsvService::PRODUCTOS);
|
||
|
return $csv->getRecords();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|