summaryrefslogtreecommitdiff
path: root/engine/Response.php
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2022-07-09 19:40:17 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-07-09 19:40:17 +0300
commitf7bfdf58def6aadc922e1632f407d1418269a0d7 (patch)
treed7a0b2819e6a26c11d40ee0b27267ea827fbb345 /engine/Response.php
initial
Diffstat (limited to 'engine/Response.php')
-rw-r--r--engine/Response.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/engine/Response.php b/engine/Response.php
new file mode 100644
index 0000000..6250063
--- /dev/null
+++ b/engine/Response.php
@@ -0,0 +1,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);
+ }
+
+} \ No newline at end of file