1 | <?php |
||
25 | class Response extends ResponseFactory |
||
26 | { |
||
27 | /** |
||
28 | * @var string HTTP body |
||
29 | */ |
||
30 | protected $body = ''; |
||
31 | |||
32 | /** |
||
33 | * @var string charset |
||
34 | */ |
||
35 | protected $charset = 'utf-8'; |
||
36 | |||
37 | /** |
||
38 | * @var array HTTP-headers |
||
39 | */ |
||
40 | protected $headers = []; |
||
41 | |||
42 | /** |
||
43 | * @var int HTTP status code |
||
44 | */ |
||
45 | protected $statusCode = 200; |
||
46 | |||
47 | /** |
||
48 | * redirect to another URL |
||
49 | * |
||
50 | * @param string $url URL |
||
51 | * @param int $statusCode |
||
52 | */ |
||
53 | 1 | public function redirect($url, $statusCode = 302) |
|
61 | |||
62 | /** |
||
63 | * set the response body |
||
64 | * |
||
65 | * @param string $body |
||
66 | * @return $this |
||
67 | */ |
||
68 | 2 | public function setBody(string $body): self |
|
73 | |||
74 | /** |
||
75 | * set the response character-set |
||
76 | * |
||
77 | * @param string $charset |
||
78 | * @return $this |
||
79 | */ |
||
80 | 5 | public function setCharset(string $charset): self |
|
85 | |||
86 | /** |
||
87 | * set a response HTTP-header |
||
88 | * |
||
89 | * @param string $key |
||
90 | * @param string $value |
||
91 | * @param bool $clear clear out any existing headers |
||
92 | * @return $this |
||
93 | */ |
||
94 | 1 | public function setHeader($key, $value, $clear = false) |
|
102 | |||
103 | /** |
||
104 | * set the response HTTP status code |
||
105 | * |
||
106 | * @param int $code |
||
107 | * @return $this |
||
108 | */ |
||
109 | public function setStatusCode($code) |
||
114 | |||
115 | /** |
||
116 | * sends the HTTP response |
||
117 | * |
||
118 | * @return $this |
||
119 | */ |
||
120 | 3 | public function send() |
|
130 | |||
131 | /** |
||
132 | * helper for easy testing |
||
133 | */ |
||
134 | public function stop() |
||
138 | |||
139 | /** |
||
140 | * output all set response headers |
||
141 | */ |
||
142 | 2 | protected function outputHeader() |
|
148 | } |
||
149 |