commit | author | age
|
15e03a
|
1 |
<?php |
F |
2 |
|
|
3 |
declare(strict_types= 1); |
|
4 |
|
|
5 |
namespace Framework; |
|
6 |
|
|
7 |
class Response { |
|
8 |
private string $body=""; |
|
9 |
|
|
10 |
private array $headers = []; |
|
11 |
|
|
12 |
private int $status_code = 0; |
|
13 |
|
|
14 |
public function setStatusCode(int $code) : void { |
|
15 |
$this->status_code = $code; |
|
16 |
} |
|
17 |
|
|
18 |
public function redirect(string $url): void { |
|
19 |
$this->addHeader("Location: $url"); |
|
20 |
} |
|
21 |
|
|
22 |
public function addHeader(string $header): void { |
|
23 |
$this->headers[] = $header; |
|
24 |
} |
|
25 |
|
|
26 |
public function setBody(string $body) : void { |
|
27 |
$this->body=$body; |
|
28 |
} |
|
29 |
|
|
30 |
public function getBody() : string { |
|
31 |
return $this->body; |
|
32 |
} |
|
33 |
|
|
34 |
public function send() : void { |
|
35 |
|
|
36 |
if($this->status_code) { |
|
37 |
http_response_code( $this->status_code ); |
|
38 |
} |
|
39 |
|
|
40 |
|
|
41 |
foreach ($this->headers as $header) { |
|
42 |
header($header); |
|
43 |
} |
|
44 |
|
|
45 |
echo $this->body; |
|
46 |
} |
|
47 |
|
|
48 |
} |