|
1 | 1 | <?php namespace Herbert\Framework; |
2 | 2 |
|
| 3 | +use Illuminate\Http\Request; |
| 4 | + |
3 | 5 | /** |
4 | 6 | * @see http://getherbert.com |
5 | 7 | */ |
6 | | -class Http { |
7 | | - |
8 | | - /** |
9 | | - * @var array |
10 | | - */ |
11 | | - protected static $methods = [ |
12 | | - 'GET', |
13 | | - 'POST', |
14 | | - 'PUT', |
15 | | - 'PATCH', |
16 | | - 'DELETE' |
17 | | - ]; |
18 | | - |
19 | | - /** |
20 | | - * @var string |
21 | | - */ |
22 | | - protected $method; |
23 | | - |
24 | | - /** |
25 | | - * @var array |
26 | | - */ |
27 | | - protected $bag; |
28 | | - |
29 | | - /** |
30 | | - * Builds up the bag and sets the method. |
31 | | - * |
32 | | - * @param array $bag |
33 | | - */ |
34 | | - public function __construct($bag = null) |
35 | | - { |
36 | | - $this->bag = $bag ?: $this->collectBag(); |
37 | | - $this->method = $_SERVER['REQUEST_METHOD']; |
38 | | - |
39 | | - if (isset($_POST['_method']) && in_array(strtoupper($_POST['_method']), static::$methods)) |
40 | | - { |
41 | | - $this->method = strtoupper($_POST['_method']); |
42 | | - } |
43 | | - } |
44 | | - |
45 | | - /** |
46 | | - * Gets the HTTP method. |
47 | | - * |
48 | | - * @return mixed |
49 | | - */ |
50 | | - public function method() |
51 | | - { |
52 | | - return $this->method; |
53 | | - } |
54 | | - |
55 | | - /** |
56 | | - * Checks if a key exists. |
57 | | - * |
58 | | - * @param $key |
59 | | - * @return bool |
60 | | - */ |
61 | | - public function has($key) |
62 | | - { |
63 | | - return isset($this->bag[$key]); |
64 | | - } |
65 | | - |
66 | | - /** |
67 | | - * Get all the keys and values. |
68 | | - * |
69 | | - * @return array |
70 | | - */ |
71 | | - public function all() |
72 | | - { |
73 | | - return array_merge($this->bag, []); |
74 | | - } |
75 | | - |
76 | | - /** |
77 | | - * Gets a key's value. |
78 | | - * |
79 | | - * @param $key |
80 | | - * @param mixed $default |
81 | | - * @return mixed |
82 | | - */ |
83 | | - public function get($key, $default = null) |
84 | | - { |
85 | | - if (!$this->has($key)) |
86 | | - { |
87 | | - return $default; |
88 | | - } |
89 | | - |
90 | | - return $this->bag[$key]; |
91 | | - } |
92 | | - |
93 | | - /** |
94 | | - * Sets a key's value. |
95 | | - * |
96 | | - * @param $key |
97 | | - * @param $value |
98 | | - * @return void |
99 | | - */ |
100 | | - public function set($key, $value) |
101 | | - { |
102 | | - $this->bag[$key] = $value; |
103 | | - } |
104 | | - |
105 | | - /** |
106 | | - * Merges two bags. |
107 | | - * |
108 | | - * @param array $bag |
109 | | - */ |
110 | | - public function put($bag = []) |
111 | | - { |
112 | | - $this->bag = array_merge($this->bag, $bag); |
113 | | - } |
114 | | - |
115 | | - /** |
116 | | - * Forgets a key. |
117 | | - * |
118 | | - * @param $key |
119 | | - * @return mixed |
120 | | - */ |
121 | | - public function forget($key) |
122 | | - { |
123 | | - if (!$this->has($key)) |
124 | | - { |
125 | | - return null; |
126 | | - } |
127 | | - |
128 | | - $value = $this->get($key); |
129 | | - unset($this->bag[$key]); |
130 | | - |
131 | | - return $value; |
132 | | - } |
| 8 | +class Http extends Request { |
133 | 9 |
|
134 | | - /** |
135 | | - * Collects the current bag. |
136 | | - * |
137 | | - * @return mixed |
138 | | - */ |
139 | | - protected function collectBag() |
140 | | - { |
141 | | - return $_SERVER['REQUEST_METHOD'] === 'POST' ? $_POST : $_GET; |
142 | | - } |
| 10 | + // |
143 | 11 |
|
144 | 12 | } |
0 commit comments