| Total Complexity | 12 |
| Total Lines | 64 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | class Request |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * gets the data from a get or a post request |
||
| 17 | * @param $key |
||
| 18 | * @return mixed |
||
| 19 | * @throws \Exception |
||
| 20 | */ |
||
| 21 | public function getData($key) |
||
| 31 | } |
||
| 32 | |||
| 33 | public function getUri(){ |
||
| 34 | return $_SERVER['REQUEST_URI']; |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * checks if the request is a XML HTTP REQUEST |
||
| 39 | * @return bool |
||
| 40 | */ |
||
| 41 | public function isXmlRequest() |
||
| 42 | { |
||
| 43 | if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') { |
||
| 44 | return true; |
||
| 45 | } |
||
| 46 | return false; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * gets the referer of the request |
||
| 51 | * @return string|null |
||
| 52 | */ |
||
| 53 | public function getReferer() |
||
| 54 | { |
||
| 55 | return $_SERVER['HTTP_REFERER'] ?? null; |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * constructs the base url of the site |
||
| 60 | * @return string |
||
| 61 | */ |
||
| 62 | public function getBaseUrl(): string |
||
| 63 | { |
||
| 64 | $host = $_SERVER['HTTP_HOST']; |
||
| 65 | $https = !empty($_SERVER['HTTPS']) ? 'https' : 'http'; |
||
| 66 | return $https . '://' . $host . '/'; |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Gettint the headers |
||
| 71 | * @return array |
||
| 72 | */ |
||
| 73 | public function getHeaders(): array |
||
| 76 | } |
||
| 77 | |||
| 78 | } |