Skip to content

Commit f95e71c

Browse files
[Export] Fix csv invalid values casting
1 parent b79c773 commit f95e71c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/Exporter/CsvExporter.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ protected function getFormat(): string
3434

3535
public function export(array $data): string
3636
{
37+
$data = $this->normalizeValues($data);
3738
$filename = $this->generateFilePath(self::FORMAT);
3839

3940
try {
@@ -46,4 +47,24 @@ public function export(array $data): string
4647

4748
return $filename;
4849
}
50+
51+
// TODO: Temporary bugfix, should be extracted into a serializer/normalizer system
52+
private function normalizeValues(array $data): array
53+
{
54+
$dataCount = count($data);
55+
for ($i = 0; $i < $dataCount; ++$i) {
56+
foreach ($data[$i] as $field => $value) {
57+
if ($value instanceof \DateTime) {
58+
$data[$i][$field] = $value->format(\DATE_ATOM);
59+
60+
continue;
61+
}
62+
if (is_object($value) || is_array($value)) {
63+
$data[$i][$field] = json_encode($value);
64+
}
65+
}
66+
}
67+
68+
return $data;
69+
}
4970
}

0 commit comments

Comments
 (0)