Total Complexity | 8 |
Total Lines | 94 |
Duplicated Lines | 0 % |
Changes | 5 | ||
Bugs | 2 | Features | 0 |
1 | <?php |
||
5 | class Request |
||
6 | { |
||
7 | /** |
||
8 | * HTTP request's data. |
||
9 | * |
||
10 | * @var array |
||
11 | */ |
||
12 | protected $requestData = []; |
||
13 | |||
14 | /** |
||
15 | * HTTP POST data. |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $postData = []; |
||
20 | |||
21 | /** |
||
22 | * HTTP GET data. |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $getData = []; |
||
27 | |||
28 | /** |
||
29 | * Overwritten methods |
||
30 | * @var array |
||
31 | */ |
||
32 | protected static $overwrittenMethods = []; |
||
33 | |||
34 | /** |
||
35 | * Request constructor. |
||
36 | */ |
||
37 | public function __construct() |
||
38 | { |
||
39 | $this->requestData = $_REQUEST; |
||
40 | $this->postData = $_POST; |
||
41 | $this->getData = $_GET; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Retrieve HTTP request data. |
||
46 | * |
||
47 | * @param string $name |
||
48 | * |
||
49 | * @return mixed|null |
||
50 | */ |
||
51 | public static function input(string $name) |
||
52 | { |
||
53 | if (isset(static::$overwrittenMethods['input'])) { |
||
54 | return (static::$overwrittenMethods['input'])($name); |
||
55 | } |
||
56 | |||
57 | return (new static)->requestData[$name] ?? null; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Retrieve HTTP POST data. |
||
62 | * |
||
63 | * @param string $name |
||
64 | * |
||
65 | * @return mixed|null |
||
66 | */ |
||
67 | public static function post(string $name) |
||
68 | { |
||
69 | if (isset(static::$overwrittenMethods['post'])) { |
||
70 | return (static::$overwrittenMethods['post'])($name); |
||
71 | } |
||
72 | |||
73 | return (new static)->postData[$name] ?? null; |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * Retrieve HTTP GET data. |
||
78 | * |
||
79 | * @param string $name |
||
80 | * |
||
81 | * @return mixed|null |
||
82 | */ |
||
83 | public static function get(string $name) |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @param string $method |
||
94 | * @param $callback |
||
95 | */ |
||
96 | public static function overwrite($method, $callback) |
||
99 | } |
||
100 | } |
||
101 |