File tree 1 file changed +32
-3
lines changed
1 file changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ final class HttpRequest
46
46
* @var HttpUrl
47
47
*/
48
48
private $ url = null ;
49
-
49
+
50
50
//for CurlHttpClient if you need to send raw CURLOPT_POSTFIELDS
51
51
private $ body = null ;
52
52
@@ -55,7 +55,36 @@ final class HttpRequest
55
55
**/
56
56
public static function create ()
57
57
{
58
- return new self ;
58
+ return new static ();
59
+ }
60
+
61
+ /**
62
+ * @return HttpRequest
63
+ **/
64
+ public static function createFromGlobals ()
65
+ {
66
+ $ request =
67
+ static ::create ()->
68
+ setGet ($ _GET )->
69
+ setPost ($ _POST )->
70
+ setServer ($ _SERVER )->
71
+ setCookie ($ _COOKIE )->
72
+ setFiles ($ _FILES );
73
+
74
+ if (isset ($ _SESSION ))
75
+ $ request ->setSession ($ _SESSION );
76
+
77
+ foreach ($ _SERVER as $ name => $ value )
78
+ if (substr ($ name , 0 , 5 ) === 'HTTP_ ' )
79
+ $ request ->setHeaderVar (substr ($ name , 5 ), $ value );
80
+
81
+ if (
82
+ $ request ->hasServerVar ('CONTENT_TYPE ' )
83
+ && $ request ->getServerVar ('CONTENT_TYPE ' ) !== 'application/x-www-form-urlencoded '
84
+ )
85
+ $ request ->setBody (file_get_contents ('php://input ' ));
86
+
87
+ return $ request ;
59
88
}
60
89
61
90
public function &getGet ()
@@ -147,7 +176,7 @@ public function hasServerVar($name)
147
176
public function setServer (array $ server )
148
177
{
149
178
$ this ->server = $ server ;
150
-
179
+
151
180
return $ this ;
152
181
}
153
182
You can’t perform that action at this time.
0 commit comments