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; + } }