1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace Src;
- use Error;
- class Request
- {
- protected array $body;
- public string $method;
- public array $headers;
- public array $post;
- public string $url;
- public function __construct()
- {
- $this->body = $_REQUEST;
- $this->method = $_SERVER['REQUEST_METHOD'];
- $this->url = $_SERVER['REQUEST_URI'];
- $this->headers = getallheaders() ?? [];
- $this->post = $_POST;
- }
- public function all(): array
- {
- return $this->body + $this->files();
- }
- public function set($field, $value): void
- {
- $this->body[$field] = $value;
- }
- public function get($field)
- {
- return $this->body[$field];
- }
- public function files(): array
- {
- return $_FILES;
- }
- public function __get($key)
- {
- if (array_key_exists($key, $this->body)) {
- return $this->body[$key];
- }
- throw new Error('Accessing a non-existent property');
- }
- }
|