1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- namespace Src;
- use Error;
- class Request {
- protected array $body;
- public string $method;
- public array $headers;
- public function __construct()
- {
- $this->body = $_REQUEST;
- $this->method = $_SERVER['REQUEST_METHOD'];
- $this->headers = getallheaders() ?? [];
- }
- 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('Acessing a non-existent property');
- }
- }
|