From f95e71ced4ab98d559c0e28728ba6edd2243be94 Mon Sep 17 00:00:00 2001 From: Jan Goralski Date: Wed, 2 Jul 2025 17:05:33 +0200 Subject: [PATCH] [Export] Fix csv invalid values casting --- src/Exporter/CsvExporter.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Exporter/CsvExporter.php b/src/Exporter/CsvExporter.php index 6fc0ac1..151d35b 100644 --- a/src/Exporter/CsvExporter.php +++ b/src/Exporter/CsvExporter.php @@ -34,6 +34,7 @@ protected function getFormat(): string public function export(array $data): string { + $data = $this->normalizeValues($data); $filename = $this->generateFilePath(self::FORMAT); try { @@ -46,4 +47,24 @@ public function export(array $data): string return $filename; } + + // TODO: Temporary bugfix, should be extracted into a serializer/normalizer system + private function normalizeValues(array $data): array + { + $dataCount = count($data); + for ($i = 0; $i < $dataCount; ++$i) { + foreach ($data[$i] as $field => $value) { + if ($value instanceof \DateTime) { + $data[$i][$field] = $value->format(\DATE_ATOM); + + continue; + } + if (is_object($value) || is_array($value)) { + $data[$i][$field] = json_encode($value); + } + } + } + + return $data; + } }