blob: 62500635e5a2a5349efeb5e1fd5e8fb2402fef19 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
<?php
class Response {
protected array $headers = [];
public function __construct(
public int $code = 200,
public ?string $body = null
) {}
public function send(): void {
$this->setHeaders();
if ($this->code == 200 || $this->code >= 400)
echo $this->body;
}
public function addHeader(string $header): void {
$this->headers[] = $header;
}
public function setHeaders(): void {
http_response_code($this->code);
foreach ($this->headers as $header)
header($header);
}
}
|