Passed
Push — master ( ab2034...9ae42c )
by Radu
01:57
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
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
namespace WebServCo\Framework\Files;
3
4
abstract class AbstractFile
5
{
6
    protected $fileName;
7
    protected $fileData;
8
    protected $contentType;
9
10
    public function __construct($fileName, $fileData, $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
    public function getOutputResponse()
40
    {
41
        return new \WebServCo\Framework\HttpResponse(
42
            $this->fileData,
43
            200,
44
            [
45
                'Last-Modified' => gmdate('D, d M Y H:i:s') . ' GMT',
46
                'ETag' => md5($this->fileData),
47
                'Accept-Ranges' => 'bytes',
48
                'Cache-Control' => 'public',
49
                'Content-Type' => $this->contentType,
50
                'Content-Transfer-Encoding' => 'binary',
51
            ]
52
        );
53
    }
54
55
    public function getFileData()
56
    {
57
        return $this->fileData;
58
    }
59
}
60