1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace suda\swoole; |
5
|
|
|
|
6
|
|
|
use suda\framework\http\Cookie; |
7
|
|
|
use suda\framework\http\Stream; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class Response |
11
|
|
|
* @package suda\swoole |
12
|
|
|
*/ |
13
|
|
|
class Response implements \suda\framework\http\Response |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var bool |
17
|
|
|
*/ |
18
|
|
|
protected $send = false; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var \Swoole\Http\Response |
22
|
|
|
*/ |
23
|
|
|
protected $response; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var int |
27
|
|
|
*/ |
28
|
|
|
protected $status = 200; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Response constructor. |
32
|
|
|
* @param \Swoole\Http\Response $response |
33
|
|
|
*/ |
34
|
|
|
public function __construct(\Swoole\Http\Response $response) |
35
|
|
|
{ |
36
|
|
|
$this->response = $response; |
37
|
|
|
$this->send = false; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* 设置状态码 |
43
|
|
|
* |
44
|
|
|
* @param integer $statusCode |
45
|
|
|
* @return \suda\framework\http\Response |
46
|
|
|
*/ |
47
|
|
|
public function status(int $statusCode) |
48
|
|
|
{ |
49
|
|
|
$this->response->status($statusCode); |
50
|
|
|
$this->status = $statusCode; |
51
|
|
|
return $this; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* 判断是否发送 |
56
|
|
|
* |
57
|
|
|
* @return boolean |
58
|
|
|
*/ |
59
|
|
|
public function isSend(): bool |
60
|
|
|
{ |
61
|
|
|
return $this->send; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* 设置头部信息 |
66
|
|
|
* |
67
|
|
|
* @param string $name |
68
|
|
|
* @param string $value |
69
|
|
|
* @param bool $replace |
70
|
|
|
* @param bool $ucfirst |
71
|
|
|
* @return \suda\framework\http\Response |
72
|
|
|
*/ |
73
|
|
|
public function header(string $name, string $value, bool $replace = false, bool $ucfirst = true) |
74
|
|
|
{ |
75
|
|
|
$this->response->header($name, $value, $ucfirst); |
|
|
|
|
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* 设置Cookie信息 |
81
|
|
|
* |
82
|
|
|
* @param Cookie $cookie |
83
|
|
|
* @return \suda\framework\http\Response |
84
|
|
|
*/ |
85
|
|
|
public function cookie(Cookie $cookie) |
86
|
|
|
{ |
87
|
|
|
$this->response->cookie( |
88
|
|
|
$cookie->getName(), |
89
|
|
|
$cookie->getValue(), |
90
|
|
|
$cookie->getExpire(), |
91
|
|
|
$cookie->getPath(), |
92
|
|
|
$cookie->getDomain(), |
93
|
|
|
$cookie->isSecure() |
94
|
|
|
); |
95
|
|
|
return $this; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* 写数据 |
100
|
|
|
* |
101
|
|
|
* @param Stream|string $data |
102
|
|
|
* @return void |
103
|
|
|
*/ |
104
|
|
|
public function write($data) |
105
|
|
|
{ |
106
|
|
|
$this->response->write($data); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* 发送数据 |
111
|
|
|
* |
112
|
|
|
* @param Stream|string $data |
113
|
|
|
* @return void |
114
|
|
|
*/ |
115
|
|
|
public function send($data) |
116
|
|
|
{ |
117
|
|
|
$this->send = true; |
118
|
|
|
$this->response->end($data); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* 发送文件内容 |
123
|
|
|
* |
124
|
|
|
* @param string $filename |
125
|
|
|
* @param integer $offset |
126
|
|
|
* @param integer $length |
127
|
|
|
* @return void |
128
|
|
|
*/ |
129
|
|
|
public function sendFile(string $filename, int $offset = 0, int $length = null) |
130
|
|
|
{ |
131
|
|
|
$this->send = true; |
132
|
|
|
$this->response->sendfile($filename, $offset, $length); |
|
|
|
|
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* 跳转 |
137
|
|
|
* |
138
|
|
|
* @param string $url |
139
|
|
|
* @param integer $httpCode |
140
|
|
|
* @return void |
141
|
|
|
*/ |
142
|
|
|
public function redirect(string $url, int $httpCode = 302) |
143
|
|
|
{ |
144
|
|
|
$this->response->redirect($url, $httpCode); |
|
|
|
|
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* 设置响应版本 |
149
|
|
|
* |
150
|
|
|
* @param string $version |
151
|
|
|
* @return \suda\framework\http\Response |
152
|
|
|
*/ |
153
|
|
|
public function version(string $version) |
154
|
|
|
{ |
155
|
|
|
return $this; |
156
|
|
|
} |
157
|
|
|
} |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.