Total Complexity | 11 |
Total Lines | 60 |
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) |
||
22 | { |
||
23 | $requestMethod = $_SERVER['REQUEST_METHOD']; |
||
24 | if ($requestMethod === 'GET') { |
||
25 | return $_GET[$key] ?? null; |
||
26 | } |
||
27 | if ($requestMethod === 'POST') { |
||
28 | return $_POST[$key] ?? null; |
||
29 | } |
||
30 | throw new \Exception("Unknown Request Method"); |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * checks if the request is a XML HTTP REQUEST |
||
35 | * @return bool |
||
36 | */ |
||
37 | public function isXmlRequest() |
||
38 | { |
||
39 | if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') { |
||
40 | return true; |
||
41 | } |
||
42 | return false; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * gets the referer of the request |
||
47 | * @return string|null |
||
48 | */ |
||
49 | public function getReferer() |
||
50 | { |
||
51 | return $_SERVER['HTTP_REFERER'] ?? null; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * constructs the base url of the site |
||
56 | * @return string |
||
57 | */ |
||
58 | public function getBaseUrl(): string |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Gettint the headers |
||
67 | * @return array |
||
68 | */ |
||
69 | public function getHeaders(): array |
||
74 | } |