mirror of
https://github.com/getgrav/grav.git
synced 2026-07-08 10:03:03 +02:00
Improved CvsFormatter to attempt to encode non-scalar variables into JSON before giving up
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
|
||||
1. [](#new)
|
||||
* Added new `onAfterCacheClear` event
|
||||
1. [](#improved)
|
||||
* Improved `CvsFormatter` to attempt to encode non-scalar variables into JSON before giving up
|
||||
1. [](#bugfix)
|
||||
* Fixed `MediaUploadTrait::copyUploadedFile()` not adding uploaded media to the collection
|
||||
* Fixed regression in saving media to a new Flex Object [admin#1867](https://github.com/getgrav/grav-plugin-admin/issues/1867)
|
||||
|
||||
@@ -123,6 +123,19 @@ class CsvFormatter extends AbstractFormatter
|
||||
protected function encodeLine(array $line, string $delimiter): string
|
||||
{
|
||||
foreach ($line as $key => &$value) {
|
||||
// Oops, we need to convert the line to a string.
|
||||
if (!\is_scalar($value)) {
|
||||
if (is_array($value) || $value instanceof \JsonSerializable || $value instanceof \stdClass) {
|
||||
$value = json_encode($value);
|
||||
} elseif (is_object($value)) {
|
||||
if (method_exists($value, 'toJson')) {
|
||||
$value = $value->toJson();
|
||||
} elseif (method_exists($value, 'toArray')) {
|
||||
$value = json_encode($value->toArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$value = $this->escape((string)$value);
|
||||
}
|
||||
unset($value);
|
||||
|
||||
Reference in New Issue
Block a user