1 | <?php |
||
5 | class Downloader extends Writer |
||
6 | { |
||
7 | /** |
||
8 | * Default headers used to tell client the response is |
||
9 | * a downloadable, non-cacheable file. |
||
10 | * @var array |
||
11 | */ |
||
12 | protected $responseHeaders = [ |
||
13 | 'Content-Type' => 'text/csv', |
||
14 | 'Content-Description' => 'File Transfer', |
||
15 | 'Content-Transfer-Encoding' => 'Binary', |
||
16 | 'Expires' => '0', |
||
17 | 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', |
||
18 | 'Pragma' => 'public', |
||
19 | ]; |
||
20 | |||
21 | protected $filename; |
||
22 | |||
23 | public function __construct($filename, $responseHeaders = []) |
||
32 | |||
33 | public static function download($file, $data) |
||
39 | |||
40 | /** |
||
41 | * Attempts to send the file as a download to the client. |
||
42 | * |
||
43 | * @throws \Exception |
||
44 | */ |
||
45 | public function sendResponse() |
||
60 | |||
61 | public function getResponseHeaders() |
||
65 | |||
66 | public function addResponseHeaders($headers = []) |
||
74 | |||
75 | public function addResponseHeader($key, $value) |
||
79 | |||
80 | public function removeResponseHeader($key) |
||
84 | |||
85 | /** |
||
86 | * @return string |
||
87 | */ |
||
88 | public function getFilename() |
||
92 | |||
93 | /** |
||
94 | * @param string $filename |
||
95 | * |
||
96 | * @return Downloader |
||
97 | */ |
||
98 | public function setFilename($filename) |
||
104 | } |
||
105 |