1 | <?php |
||
28 | class Response implements ResponseFactoryInterface |
||
29 | { |
||
30 | /** |
||
31 | * @var string HTTP body |
||
32 | */ |
||
33 | protected $body = ''; |
||
34 | |||
35 | /** |
||
36 | * @var string charset |
||
37 | */ |
||
38 | protected $charset = 'utf-8'; |
||
39 | |||
40 | /** |
||
41 | * @var array HTTP-headers |
||
42 | */ |
||
43 | protected $headers = []; |
||
44 | |||
45 | /** |
||
46 | * @var int HTTP status code |
||
47 | */ |
||
48 | protected $statusCode = 200; |
||
49 | |||
50 | /** |
||
51 | * Creates a PSR-7 response |
||
52 | */ |
||
53 | 1 | public function createResponse($code = 200) |
|
57 | |||
58 | /** |
||
59 | * Creates PSR-7 HTML response |
||
60 | */ |
||
61 | 3 | public function createHtmlResponse($body, $code = 200) |
|
65 | |||
66 | /** |
||
67 | * Creates PSR-7 redirect response |
||
68 | */ |
||
69 | 1 | public function createRedirectResponse($url, $code = 302) |
|
73 | |||
74 | /** |
||
75 | * redirect to another URL |
||
76 | * |
||
77 | * @param string $url URL |
||
78 | * @param int $statusCode |
||
79 | */ |
||
80 | 1 | public function redirect($url, $statusCode = 302) |
|
88 | |||
89 | /** |
||
90 | * set the response body |
||
91 | * |
||
92 | * @param $body |
||
93 | * @return $this |
||
94 | */ |
||
95 | 2 | public function setBody($body) |
|
100 | |||
101 | /** |
||
102 | * set the response character-set |
||
103 | * |
||
104 | * @param $charset |
||
105 | * @return $this |
||
106 | */ |
||
107 | 5 | public function setCharset($charset) |
|
112 | |||
113 | /** |
||
114 | * set a response HTTP-header |
||
115 | * |
||
116 | * @param string $key |
||
117 | * @param string $value |
||
118 | * @param bool $clear clear out any existing headers |
||
119 | * @return $this |
||
120 | */ |
||
121 | 1 | public function setHeader($key, $value, $clear = false) |
|
129 | |||
130 | /** |
||
131 | * set the response HTTP status code |
||
132 | * |
||
133 | * @param $code |
||
134 | * @return $this |
||
135 | */ |
||
136 | public function setStatusCode($code) |
||
141 | |||
142 | /** |
||
143 | * sends the HTTP response |
||
144 | * |
||
145 | * @return $this |
||
146 | */ |
||
147 | 3 | public function send() |
|
157 | |||
158 | /** |
||
159 | * helper for easy testing |
||
160 | */ |
||
161 | public function stop() |
||
165 | |||
166 | /** |
||
167 | * output all set response headers |
||
168 | */ |
||
169 | 2 | protected function outputHeader() |
|
175 | } |
||
176 |