. */ declare(strict_types=1); namespace FireflyIII\Export\Exporter; use FireflyIII\Export\Entry\Entry; use Illuminate\Support\Facades\Storage; use League\Csv\Writer; /** * 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 { // choose file name: $this->fileName = $this->job->key . '-records.csv'; //we create the CSV into memory $writer = Writer::createFromString(''); $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); $disk = Storage::disk('export'); $disk->put($this->fileName, $writer->getContent()); return true; } }