diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2026-05-24 14:16:07 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2026-05-24 14:16:07 +0300 |
| commit | 1bdf80397c19362c019cdd231e8813e251764370 (patch) | |
| tree | 126c1e0ffcc5664ac2b5883bec64007070411a9b /classes/Request.php | |
| parent | 1917ab77550613654620b6f5d4ad8570704246de (diff) | |
| download | the-epube-1bdf80397c19362c019cdd231e8813e251764370.tar.gz the-epube-1bdf80397c19362c019cdd231e8813e251764370.tar.xz | |
switch to PSR-4 router with namespaced handlers
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; + } +} |
