From 6df3d321d9b67c4541f50158b087d37c4b22e886 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 12 Nov 2023 11:16:56 +0100 Subject: initial commit --- src/Request.php | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/Request.php (limited to 'src/Request.php') diff --git a/src/Request.php b/src/Request.php new file mode 100644 index 0000000..586134d --- /dev/null +++ b/src/Request.php @@ -0,0 +1,48 @@ +scheme = $requestUrl['scheme']; + $this->host = $requestUrl['host']; + $this->path = $requestUrl['path'] ?? '/'; + + $this->query = []; + if (isset($requestUrl['query'])) { + foreach (explode('&', $requestUrl['query']) as $queryString) { + $query = explode('=', $queryString); + $this->query[$query[0]] = $query[1] ?? null; + } + } + } + + /** + * @param resource $resource + */ + public static function fromResource($resource): static + { + return Request::fromString(fread($resource, 1024)); + } + + public static function fromString(string $string): static + { + $requestUrl = explode("\r\n", $string)[0] ?? ''; + + return new Request($requestUrl); + } + + public function getPath(): string + { + return $this->path; + } +} -- cgit v1.2.3