Passed
Push — dev ( a19e2c...857e61 )
by 世昌
03:17
created

ResponseWrapper::header()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 4
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
4
namespace suda\framework\response;
5
6
use suda\framework\http\Cookie;
7
use suda\framework\http\Response;
8
use suda\framework\http\Stream;
9
10
class ResponseWrapper implements Response
11
{
12
    /**
13
     * @var Response
14
     */
15
    protected $response;
16
17
    /**
18
     * @varint
19
     */
20
    protected $status = 200;
21
22
    /**
23
     * 创建响应
24
     * @param Response $response
25
     */
26
    public function __construct(Response $response)
27
    {
28
        $this->status = 200;
29
        $this->response = $response;
30
    }
31
32
    /**
33
     * 设置状态码
34
     *
35
     * @param integer $statusCode
36
     * @return Response
37
     */
38
    public function status(int $statusCode)
39
    {
40
        $this->status = $statusCode;
41
        $this->response->status($statusCode);
42
        return $this;
43
    }
44
45
46
    /**
47
     * 获取状态码
48
     *
49
     * @return integer
50
     */
51
    public function getStatus():int
52
    {
53
        return $this->status;
54
    }
55
56
57
    /**
58
     * 设置响应版本
59
     *
60
     * @param string $version
61
     * @return $this
62
     */
63
    public function version(string $version)
64
    {
65
        $this->response->version($version);
66
        return $this;
67
    }
68
69
    /**
70
     * 判断是否发送
71
     *
72
     * @return boolean
73
     */
74
    public function isSend(): bool
75
    {
76
        return $this->response->isSend();
77
    }
78
79
    /**
80
     * 设置头部信息
81
     *
82
     * @param string $name
83
     * @param string $value
84
     * @param bool $replace
85
     * @param bool $ucfirst
86
     * @return $this
87
     */
88
    public function header(string $name, string $value, bool $replace = false, bool $ucfirst = true)
89
    {
90
        $this->response->header($name, $value, $replace, $ucfirst);
91
        return $this;
92
    }
93
94
    /**
95
     * 设置Cookie信息
96
     *
97
     * @param Cookie $cookie
98
     * @return $this
99
     */
100
    public function cookie(Cookie $cookie)
101
    {
102
        $this->response->cookie($cookie);
103
        return $this;
104
    }
105
106
    /**
107
     * 写数据
108
     *
109
     * @param Stream|string $data
110
     * @return void
111
     */
112
    public function write($data)
113
    {
114
        $this->response->write($data);
115
    }
116
117
    /**
118
     * 发送数据
119
     *
120
     * @param Stream|string $data
121
     * @return void
122
     */
123
    public function send($data)
124
    {
125
        $this->response->send($data);
126
    }
127
128
    /**
129
     * 跳转
130
     *
131
     * @param string $url
132
     * @param integer $httpCode
133
     * @return void
134
     */
135
    public function redirect(string $url, int $httpCode = 302)
136
    {
137
        $this->response->redirect($url, $httpCode);
138
    }
139
140
    /**
141
     * 发送文件内容
142
     *
143
     * @param string $filename
144
     * @param integer $offset
145
     * @param integer $length
146
     * @return void
147
     */
148
    public function sendFile(string $filename, int $offset = 0, int $length = null)
149
    {
150
        $this->response->sendFile($filename, $offset, $length);
151
    }
152
}
153