. */ declare(strict_types=1); namespace FireflyIII\Export\Exporter; use FireflyIII\Export\Entry\Entry; use League\Csv\Writer; use Storage; /** * Class CsvExporter. * * @codeCoverageIgnore * @deprecated */ class CsvExporter extends BasicExporter implements ExporterInterface { /** @var string Filename */ private $fileName; /** * Get file name. * * @return string */ public function getFileName(): string { return $this->fileName; } /** * Run collector. * * @return bool * */ public function run(): bool { // create temporary file: $this->tempFile(); // necessary for CSV writer: $fullPath = storage_path('export') . DIRECTORY_SEPARATOR . $this->fileName; //we create the CSV into memory $writer = Writer::createFromPath($fullPath); $rows = []; // get field names for header row: $first = $this->getEntries()->first(); $headers = []; if (null !== $first) { $headers = array_keys(get_object_vars($first)); } $rows[] = $headers; /** @var Entry $entry */ foreach ($this->getEntries() as $entry) { $line = []; foreach ($headers as $header) { $line[] = $entry->$header; } $rows[] = $line; } $writer->insertAll($rows); return true; } /** * Make a temp file. */ private function tempFile() { $this->fileName = $this->job->key . '-records.csv'; // touch file in export directory: $disk = Storage::disk('export'); $disk->put($this->fileName, ''); } }