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' => 'application/octet-stream', |
||
14 | 'Content-Description' => 'File Transfer', |
||
15 | 'Content-Transfer-Encoding' => 'Binary', |
||
16 | 'Content-Disposition' => 'attachment; filename="%s"', |
||
17 | 'Expires' => '0', |
||
18 | 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', |
||
19 | 'Pragma' => 'public', |
||
20 | 'Content-Length' => '%s', |
||
21 | ]; |
||
22 | |||
23 | protected $filename; |
||
24 | |||
25 | public function __construct($filename = '', $responseHeaders = []) |
||
36 | |||
37 | public function getResponseHeaders() |
||
41 | |||
42 | public function addResponseHeaders($userHeaders = []) |
||
50 | |||
51 | public function addResponseHeader($key, $value) |
||
55 | |||
56 | public function removeResponseHeader($key) |
||
60 | |||
61 | /** |
||
62 | * @return string |
||
63 | */ |
||
64 | public function getFilename() |
||
68 | |||
69 | /** |
||
70 | * @param string $filename |
||
71 | * |
||
72 | * @return Downloader |
||
73 | */ |
||
74 | public function setFilename($filename) |
||
80 | |||
81 | /** |
||
82 | * Attempts to send the file as a download to the client. |
||
83 | * |
||
84 | * @throws \Exception |
||
85 | */ |
||
86 | public function download() |
||
108 | |||
109 | protected function getResponseBody() |
||
119 | } |
||
120 |