38 lines
		
	
	
		
			761 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			761 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace Top100stars\Models;
 | 
						|
 | 
						|
use Top100stars\Interfaces\IGitTop100CSV;
 | 
						|
 | 
						|
class GitTop100 implements IGitTop100CSV {
 | 
						|
    private $csv = null;
 | 
						|
 | 
						|
    public function __construct(?string $fileName) {
 | 
						|
        if ($fileName!=null) $this->loadCSV($fileName);
 | 
						|
    }
 | 
						|
 | 
						|
    private function loadCSV(string $fileName) {
 | 
						|
        if (($gestor = fopen($fileName, "r")) !== FALSE) {
 | 
						|
            $this->csv = [];
 | 
						|
            while (($datos = fgetcsv($gestor, 1000, ",")) !== FALSE) {
 | 
						|
                $this->csv[] = $datos;
 | 
						|
            }
 | 
						|
            fclose($gestor);
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    public function setCSV($csv): IGitTop100CSV
 | 
						|
    {
 | 
						|
        $this->csv = $csv;
 | 
						|
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
    public function getCSV(): ?array {
 | 
						|
        return $this->csv;
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
}
 | 
						|
 |