aboutsummaryrefslogtreecommitdiff
path: root/lib/http.php
diff options
context:
space:
mode:
authorGravatar Dag <me@dvikan.no> 2024-01-25 16:06:24 +0100
committerGravatar GitHub <noreply@github.com> 2024-01-25 16:06:24 +0100
commitd08d13f2c87b24fadb92e31c50dedc6e56c3c088 (patch)
treea2fd66aa0cdd091ad34a135cf8222847f025f6f3 /lib/http.php
parent9574c17ddc4c55ab191878164627c4501a565221 (diff)
downloadrss-bridge-d08d13f2c87b24fadb92e31c50dedc6e56c3c088.tar.gz
rss-bridge-d08d13f2c87b24fadb92e31c50dedc6e56c3c088.tar.zst
rss-bridge-d08d13f2c87b24fadb92e31c50dedc6e56c3c088.zip
refactor: introduce http Request object (#3926)
Diffstat (limited to 'lib/http.php')
-rw-r--r--lib/http.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/http.php b/lib/http.php
index 90b65a6e..d53909b4 100644
--- a/lib/http.php
+++ b/lib/http.php
@@ -166,6 +166,46 @@ final class CurlHttpClient implements HttpClient
}
}
+final class Request
+{
+ private array $get;
+ private array $server;
+
+ private function __construct()
+ {
+ }
+
+ public static function fromGlobals(): self
+ {
+ $self = new self();
+ $self->get = $_GET;
+ $self->server = $_SERVER;
+ return $self;
+ }
+
+ public static function fromCli(array $cliArgs): self
+ {
+ $self = new self();
+ $self->get = $cliArgs;
+ return $self;
+ }
+
+ public function get(string $key, $default = null): ?string
+ {
+ return $this->get[$key] ?? $default;
+ }
+
+ public function server(string $key, string $default = null): ?string
+ {
+ return $this->server[$key] ?? $default;
+ }
+
+ public function toArray(): array
+ {
+ return $this->get;
+ }
+}
+
final class Response
{
public const STATUS_CODES = [