-
Notifications
You must be signed in to change notification settings - Fork 0
/
Request.class.php
executable file
·307 lines (225 loc) · 5.11 KB
/
Request.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<?php
namespace Disco\classes;
/**
* Information about the current request to the application.
*/
class Request {
/**
* @var string $uri The request URI.
*/
protected $uri;
/**
* @var string $url The request URL.
*/
protected $url;
/**
* @var array $pathParts The parts of the request URI.
*/
protected $pathParts = Array();
/**
* @var string $type The request type/method, eg: `POST,GET,DELETE,PUT`.
*/
protected $type;
/**
* @var string $ip The IP address of the user making the request.
*/
protected $ip;
/**
* @var boolean $secure Whether the request was made over HTTPS.
*/
protected $secure;
/**
* Pull necessary information from $_SERVER and make available on the class.
*/
public function __construct(){
$this->uri = $_SERVER['REQUEST_URI'];
$this->url = parse_url($this->uri);
$this->pathParts = explode('/',$this->url['path']);
$this->type = $_SERVER['REQUEST_METHOD'];
$this->ip = $_SERVER['REMOTE_ADDR'];
$this->secure = !empty($_SERVER['HTTPS']);
}//__construct
/**
* Get the request URI.
*
* @return string
*/
public function uri(){
return $this->uri;
}//uri
/**
* Get the request type.
*
* @return string
*/
public function type(){
return $this->type;
}//type
/**
* Get the request IP address.
*
* @return string
*/
public function ip(){
return $this->ip;
}//ip
/**
* Whether the request was made via HTTPS.
*
* @return boolean
*/
public function secure(){
return $this->secure;
}//secure
/**
* Get the url schema of the request.
*
* @return string
*/
public function scheme(){
return $this->url['scheme'];
}//scheme
/**
* Get the url host of the request.
*
* @return string
*/
public function host(){
return $this->url['host'];
}//host
/**
* Get the port of the request.
*
* @return string
*/
public function port(){
return $this->url['port'];
}//port
/**
* Get the user of the request.
*
* @return string
*/
public function user(){
return $this->url['user'];
}//user
/**
* Get the password of the request.
*
* @return string
*/
public function pass(){
return $this->url['pass'];
}//pass
/**
* Get the path of the request. The string after the domain backslash and before any get variables.
*
* @return string
*/
public function path(){
return $this->url['path'];
}//path
/**
* Get a part of the path by index.
*
* @param int $i The index of the path part.
*
* @return string
*/
public function pathPart($i){
if(isset($this->pathParts[$i])){
return $this->pathParts[$i];
}//if
return null;
}//pathPart
/**
* Get the depth of the path.
*
* @return int
*/
public function pathDepth(){
return count($this->pathParts);
}//pathDepth
/**
* Get the query of the path.
*
* @return string
*/
public function query(){
return $this->url['query'];
}//query
/**
* Get the framgment of the path.
*
* @return string
*/
public function fragment(){
return $this->url['fragment'];
}//fragment
/**
* Get a GET variable in the request.
*
* @param string $k The key.
*
* @return string
*/
public function get($k = null){
return \Data::get($k);
}//get
/**
* Get a POST variable in the request.
*
* @param string $k The key.
*
* @return string
*/
public function post($k = null){
return \Data::post($k);
}//post
/**
* Get a PUT variable in the request.
*
* @param string $k The key.
*
* @return string
*/
public function put($k = null){
return \Data::put($k);
}//put
/**
* Get a DELETE variable in the request.
*
* @param string $k The key.
*
* @return string
*/
public function delete($k = null){
return \Data::delete($k);
}//delete
/**
* Get an instance of the \Disco\classes\Data service.
*
* @return \Disco\classes\Data
*/
public function data(){
return \Data::instance();
}//data
/**
* Get the `$_SERVER` superglobal. Comes in handy when you want access to the server superglobal via Twig
* templates.
*
* @return array
*/
public function getServerGlobal(){
return $_SERVER;
}//getServerGlobal
/**
* Get the `$_REQUEST` superglobal. Comes in handy when you want access to the request superglobal via Twig
* templates.
*
* @return array
*/
public function getRequestGlobal(){
return $_REQUEST;
}//getServerGlobal
}//Request