Passed
Push — master ( 1995c6...6ecf81 )
by Radu
01:20
created

AbstractFile   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 47
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDownloadResponse() 0 18 1
A __construct() 0 5 1
A getOutputResponse() 0 12 1
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($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