diff options
Diffstat (limited to 'classes/Request.php')
| -rw-r--r-- | classes/Request.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/classes/Request.php b/classes/Request.php new file mode 100644 index 0000000..57fe862 --- /dev/null +++ b/classes/Request.php @@ -0,0 +1,49 @@ +<?php + +class Request +{ + private array $serverParams; + private array $queryParams; + private array $bodyParams; + private array $cookies; + + public function __construct() + { + $this->serverParams = $_SERVER ?? []; + $this->queryParams = $_GET ?? []; + $this->bodyParams = $_POST ?? []; + $this->cookies = $_COOKIE ?? []; + } + + public function getServerParams(): array + { + return $this->serverParams; + } + + public function getQueryParams(): array + { + return $this->queryParams; + } + + public function getParsedBody(): array + { + return array_merge($this->queryParams, $this->bodyParams); + } + + public function getCookieParams(): array + { + return $this->cookies; + } + + public function getAttribute(string $name, mixed $default = null): mixed + { + return $this->getParsedBody()[$name] ?? $default; + } + + public function withAttribute(string $name, mixed $value): self + { + $clone = clone $this; + $clone->bodyParams[$name] = $value; + return $clone; + } +} |
