| Total Complexity | 8 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | class CsvResponse extends Response |
||
| 8 | { |
||
| 9 | protected $data; |
||
| 10 | protected $filename = 'export.csv'; |
||
| 11 | |||
| 12 | public function __construct($data = array(), $status = 200, $headers = array()) |
||
| 16 | } |
||
| 17 | |||
| 18 | public function setData(array $data) |
||
| 19 | { |
||
| 20 | $output = fopen('php://temp', 'r+'); |
||
| 21 | foreach ($data as $row) { |
||
| 22 | fputcsv($output, $row); |
||
|
|
|||
| 23 | } |
||
| 24 | rewind($output); |
||
| 25 | $this->data = ''; |
||
| 26 | while ($line = fgets($output)) { |
||
| 27 | $this->data .= $line; |
||
| 28 | } |
||
| 29 | $this->data .= fgets($output); |
||
| 30 | return $this->update(); |
||
| 31 | } |
||
| 32 | |||
| 33 | public function getFilename() |
||
| 34 | { |
||
| 35 | return $this->filename; |
||
| 36 | } |
||
| 37 | |||
| 38 | public function setFilename($filename) |
||
| 42 | } |
||
| 43 | |||
| 44 | protected function update() |
||
| 52 | } |
||
| 53 | } |