*/ private array $headers = []; private string $body = ''; private string $contentType = "text/json"; public function withStatus(int $code, string $reasonPhrase = ''): self { $clone = clone $this; $clone->status = $code; return $clone; } public function withHeader(string $name, string $value): self { $clone = clone $this; $clone->headers[$name] = $value; return $clone; } public function getBody(): string { return $this->body; } public function withBody(string $body): self { $clone = clone $this; $clone->body = $body; return $clone; } public function send(): void { $contentTypeFound = false; if ($this->headers) { foreach ($this->headers as $name => $value) { header("$name: $value"); if (strtolower($name) === "content-type") $contentTypeFound = true; } } if (!$contentTypeFound) header("Content-type: {$this->contentType}"); http_response_code($this->status); echo $this->body; } }