parent
75e26f4960
commit
09ab6f38d5
@ -0,0 +1,31 @@ |
||||
<?php |
||||
|
||||
namespace SBRL; |
||||
|
||||
/** |
||||
* Serialises an object to a variety of formats. |
||||
*/ |
||||
class ResponseEncoder |
||||
{ |
||||
/** |
||||
* Encodes an array of associative arrays to CSV. |
||||
* @param array $data The data to encode. |
||||
* @return string The data encoded to csv. |
||||
*/ |
||||
public static function encode_csv($data) { |
||||
if(empty($data)) |
||||
return ""; |
||||
|
||||
$result = fopen('php://temp/maxmemory:'. (5*1024*1024), 'r+'); |
||||
fputcsv($result, array_keys($data[0])); |
||||
foreach($data as $row) |
||||
fputcsv($result, array_values($row)); |
||||
rewind($result); |
||||
|
||||
$response = \stream_get_contents($result); |
||||
|
||||
fclose($result); |
||||
|
||||
return $response; |
||||
} |
||||
} |
Loading…
Reference in new issue