You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.1 KiB
52 lines
1.1 KiB
<?php
|
|
|
|
declare(strict_types = 1);
|
|
|
|
/**
|
|
* @author Robert Strutts <Bob_586@Yahoo.com>
|
|
* @copyright (c) 2025, Robert Strutts
|
|
* @license MIT
|
|
*/
|
|
namespace CodeHydrater\http;
|
|
|
|
class response
|
|
{
|
|
protected string $content;
|
|
protected int $status_code;
|
|
protected array $headers;
|
|
|
|
public function __construct(
|
|
string $content = '',
|
|
int $status_code = 200,
|
|
array $headers = []
|
|
) {
|
|
$this->content = $content;
|
|
$this->status_code = $status_code;
|
|
$this->headers = $headers;
|
|
}
|
|
|
|
public function send(): void {
|
|
http_response_code($this->status_code);
|
|
|
|
foreach ($this->headers as $name => $value) {
|
|
header("$name: $value");
|
|
}
|
|
|
|
echo $this->content;
|
|
}
|
|
|
|
public function set_content(string $content): self {
|
|
$this->content = $content;
|
|
return $this;
|
|
}
|
|
|
|
public function set_status_code(int $code): self {
|
|
$this->status_code = $code;
|
|
return $this;
|
|
}
|
|
|
|
public function add_header(string $name, string $value): self {
|
|
$this->headers[$name] = $value;
|
|
return $this;
|
|
}
|
|
} |