28 lines
575 B
PHP
28 lines
575 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Core\Http;
|
|
|
|
class Response
|
|
{
|
|
private string $body;
|
|
private int $status;
|
|
private array $headers;
|
|
|
|
public function __construct(string $body = '', int $status = 200, array $headers = [])
|
|
{
|
|
$this->body = $body;
|
|
$this->status = $status;
|
|
$this->headers = $headers;
|
|
}
|
|
|
|
public function send(): void
|
|
{
|
|
http_response_code($this->status);
|
|
foreach ($this->headers as $name => $value) {
|
|
header($name . ': ' . $value);
|
|
}
|
|
echo $this->body;
|
|
}
|
|
}
|