Skip to content

Commit 73623cb

Browse files
committed
Use safe_get_object_vars() method that checks if $data is indeed object
1 parent 69785c9 commit 73623cb

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Controllers/ReportController.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,23 @@ public function show($slug, $id)
106106
return '<table class="report">'.$response.'</table>';
107107
}
108108

109+
private function safe_get_object_vars($data)
110+
{
111+
if (is_array($data)) {
112+
return $data;
113+
} else {
114+
return get_object_vars($data);
115+
}
116+
}
117+
109118
public function csv($slug, $id)
110119
{
111120
$this->checkSlug($slug, 'read');
112121
$data = $this->getQueryData($slug, $id);
113122
$out = fopen('php://memory', 'w');
114-
fputcsv($out, array_keys(get_object_vars($data[0])));
123+
fputcsv($out, array_keys($this->safe_get_object_vars($data[0])));
115124
foreach($data as $line) {
116-
fputcsv($out, get_object_vars($line), $this->module('download_csv_delimiter') ?: ',');
125+
fputcsv($out, $this->safe_get_object_vars($line), $this->module('download_csv_delimiter') ?: ',');
117126
}
118127
rewind($out);
119128
$csv = stream_get_contents($out);

0 commit comments

Comments
 (0)