Passed
Push — master ( 3ebd61...e5f7f7 )
by Radu
01:13
created

AbstractFile::getDownloadResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 14
nc 1
nop 0
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace WebServCo\Framework;
3
4
abstract class AbstractFile
5
{
6
    protected $fileName;
7
    protected $fileData;
8
    protected $contentType;
9
10
    public function __construct(string $fileName, string $fileData, string $contentType = 'application/octet-stream')
11
    {
12
        $this->fileName = $fileName;
13
        $this->fileData = $fileData;
14
        $this->contentType = $contentType;
15
    }
16
17
    public function getDownloadResponse()
18
    {
19
        return new \WebServCo\Framework\HttpResponse(
20
            $this->fileData,
21
            200,
22
            [
23
                'Last-Modified' => gmdate('D, d M Y H:i:s') . ' GMT',
24
                'ETag' => md5($this->fileData),
25
                'Accept-Ranges' => 'bytes',
26
                'Cache-Control' => 'public',
27
                'Content-Description' => 'File Transfer',
28
                'Content-Disposition' => sprintf(
29
                    'attachment; filename=%s',
30
                    $this->fileName
31
                ),
32
                'Content-Type' => $this->contentType,
33
                'Content-Transfer-Encoding' => 'binary',
34
                'Connection' => 'close',
35
            ]
36
        );
37
    }
38
}
39