Exemplo n.º 1
0
 /**
  * @param $path
  * @param $content
  * @throws WriteReadException
  */
 public function writeFile($path, $content)
 {
     $fileOpened = fopen($path, FilesystemManager::fopenModes()["write"]);
     if ($fileOpened !== false) {
         fputcsv($fileOpened, array_keys($content[0]));
         foreach ($content as $row) {
             fputcsv($fileOpened, $row);
         }
         fclose($fileOpened);
         return;
     }
     throw new WriteReadException(ExceptionMessage::FILE_NOT_WRITABLE, 500);
 }
Exemplo n.º 2
0
 /**
  * @param $path
  * @return array
  * @throws WriteReadException
  */
 public function readFile($path)
 {
     $results = [];
     $isHeader = true;
     $headers = [];
     $fileOpened = fopen($path, FilesystemManager::fopenModes()["read"]);
     if ($fileOpened !== false) {
         while (($row = fgetcsv($fileOpened)) !== false) {
             if ($isHeader) {
                 $isHeader = false;
                 $headers = $row;
                 continue;
             }
             $results[] = array_combine($headers, $row);
         }
         fclose($fileOpened);
         return $results;
     }
     throw new WriteReadException(ExceptionMessage::FILE_NOT_READABLE, 500);
 }
Exemplo n.º 3
0
 public function init()
 {
     parent::init();
 }