File tree Expand file tree Collapse file tree 3 files changed +15
-6
lines changed Expand file tree Collapse file tree 3 files changed +15
-6
lines changed Original file line number Diff line number Diff line change 8
8
*
9
9
* @method string|mixed get(string $name = null, mixed $default = null)
10
10
* @method string|mixed post(string $name = null, mixed $default = null)
11
+ * @method string|mixed query(string $name = null, mixed $default = null)
11
12
* @method string|mixed request(string $name = null, mixed $default = null)
12
13
* @method string|mixed server(string $name = null, mixed $default = null)
13
14
* @method string|mixed session(string $name = null, mixed $default = null)
17
18
class Request
18
19
{
19
20
/**
20
- * Just triggering the super global.
21
+ * Just triggering the super global and fill the query global .
21
22
*/
22
23
public function __construct ()
23
24
{
24
25
$ _SERVER ;
26
+ if (!in_array ($ this ->method (), ['GET ' , 'POST ' ])) {
27
+ parse_str (file_get_contents ('php://input ' ), $ GLOBALS ['_QUERY ' ]);
28
+ }
25
29
}
26
30
27
31
/**
28
32
* Return URI with query string.
29
33
*
30
34
* @return string
31
35
*/
32
- public function uri ()
36
+ public function uriWithQuery ()
33
37
{
34
- return urldecode ($ this ->plainUri ( ));
38
+ return urldecode ($ this ->server ( ' REQUEST_URI ' ));
35
39
}
36
40
37
41
/**
38
42
* Return URI without query string.
39
43
*
40
44
* @return string
41
45
*/
42
- public function plainUri ()
46
+ public function uri ()
43
47
{
44
- return explode ('? ' , $ this ->server ( ' REQUEST_URI ' ))[0 ];
48
+ return explode ('? ' , $ this ->uriWithQuery ( ))[0 ];
45
49
}
46
50
47
51
/**
Original file line number Diff line number Diff line change @@ -99,7 +99,7 @@ public function testRun()
99
99
100
100
$ app = new Application ();
101
101
$ app ->get ('/profile/{id} ' , function (Request $ request , $ id ) {
102
- echo $ request ->plainUri () . ' has id ' . $ id ;
102
+ echo $ request ->uriWithQuery () . ' has id ' . $ id ;
103
103
});
104
104
self ::assertEquals ('/profile/123 has id 123 ' , $ app ->run ());
105
105
}
Original file line number Diff line number Diff line change @@ -27,6 +27,11 @@ public function testUri()
27
27
self ::assertEquals ('/profile/123 ' , $ this ->request ->uri ());
28
28
}
29
29
30
+ public function testUriWithQuery ()
31
+ {
32
+ self ::assertEquals ('/profile/123?show=settings ' , $ this ->request ->uriWithQuery ());
33
+ }
34
+
30
35
public function testIsHttps ()
31
36
{
32
37
self ::assertEquals (false , $ this ->request ->isHttps ());
You can’t perform that action at this time.
0 commit comments