1 | <?php |
||||
2 | |||||
3 | /** |
||||
4 | * CsvExporter.php |
||||
5 | * Copyright (c) 2018 [email protected] |
||||
6 | * |
||||
7 | * This file is part of Firefly III. |
||||
8 | * |
||||
9 | * Firefly III is free software: you can redistribute it and/or modify |
||||
10 | * it under the terms of the GNU General Public License as published by |
||||
11 | * the Free Software Foundation, either version 3 of the License, or |
||||
12 | * (at your option) any later version. |
||||
13 | * |
||||
14 | * Firefly III is distributed in the hope that it will be useful, |
||||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
17 | * GNU General Public License for more details. |
||||
18 | * |
||||
19 | * You should have received a copy of the GNU General Public License |
||||
20 | * along with Firefly III. If not, see <http://www.gnu.org/licenses/>. |
||||
21 | */ |
||||
22 | |||||
23 | declare(strict_types=1); |
||||
24 | |||||
25 | namespace FireflyIII\Export\Exporter; |
||||
26 | |||||
27 | use FireflyIII\Export\Entry\Entry; |
||||
28 | use Illuminate\Support\Facades\Storage; |
||||
29 | use League\Csv\Writer; |
||||
30 | |||||
31 | /** |
||||
32 | * Class CsvExporter. |
||||
33 | * |
||||
34 | * @codeCoverageIgnore |
||||
35 | * @deprecated |
||||
36 | */ |
||||
37 | class CsvExporter extends BasicExporter implements ExporterInterface |
||||
0 ignored issues
–
show
The class
FireflyIII\Export\Exporter\BasicExporter has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
38 | { |
||||
39 | /** @var string Filename */ |
||||
40 | private $fileName; |
||||
41 | |||||
42 | /** |
||||
43 | * Get file name. |
||||
44 | * |
||||
45 | * @return string |
||||
46 | */ |
||||
47 | public function getFileName(): string |
||||
48 | { |
||||
49 | return $this->fileName; |
||||
50 | } |
||||
51 | |||||
52 | /** |
||||
53 | * Run collector. |
||||
54 | * |
||||
55 | * @return bool |
||||
56 | * |
||||
57 | */ |
||||
58 | public function run(): bool |
||||
59 | { |
||||
60 | // choose file name: |
||||
61 | $this->fileName = $this->job->key . '-records.csv'; |
||||
62 | |||||
63 | //we create the CSV into memory |
||||
64 | $writer = Writer::createFromString(''); |
||||
65 | $rows = []; |
||||
66 | |||||
67 | // get field names for header row: |
||||
68 | $first = $this->getEntries()->first(); |
||||
69 | $headers = []; |
||||
70 | if (null !== $first) { |
||||
71 | $headers = array_keys(get_object_vars($first)); |
||||
72 | } |
||||
73 | |||||
74 | $rows[] = $headers; |
||||
75 | |||||
76 | /** @var Entry $entry */ |
||||
77 | foreach ($this->getEntries() as $entry) { |
||||
78 | $line = []; |
||||
79 | foreach ($headers as $header) { |
||||
80 | $line[] = $entry->$header; |
||||
81 | } |
||||
82 | $rows[] = $line; |
||||
83 | } |
||||
84 | $writer->insertAll($rows); |
||||
85 | $disk = Storage::disk('export'); |
||||
86 | $disk->put($this->fileName, $writer->getContent()); |
||||
87 | |||||
88 | return true; |
||||
89 | } |
||||
90 | } |
||||
91 |
This interface has been deprecated. The supplier of the interface has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.