Passed
Push — dev ( b45126...5faaf1 )
by 世昌
02:13
created

FileContentWrapper   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
c 2
b 0
f 0
dl 0
loc 15
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A getWrappedContent() 0 7 1
1
<?php
2
namespace suda\framework\response\wrapper;
3
4
use suda\framework\Response;
5
use suda\framework\http\Stream;
6
use suda\framework\http\stream\DataStream;
7
use suda\framework\response\AbstractContentWrapper;
8
9
/**
10
 * 响应包装器
11
 */
12
class FileContentWrapper extends AbstractContentWrapper
13
{
14
    /**
15
     * 获取内容
16
     *
17
     * @param Response $response
18
     * @return Stream
19
     */
20
    public function getWrappedContent(Response $response): Stream
21
    {
22
        $content = $this->content;
23
        $response->setType($content->getExtension());
24
        $response->setHeader('Content-Disposition', 'attachment;filename="' . $content->getBasename().'"');
25
        $response->setHeader('Cache-Control', 'max-age=0');
26
        return new DataStream($content);
27
    }
28
}
29