File tree Expand file tree Collapse file tree 1 file changed +34
-2
lines changed Expand file tree Collapse file tree 1 file changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -40,13 +40,45 @@ final class HttpRequest
40
40
private $ method = null ;
41
41
42
42
private $ url = null ;
43
+
44
+ //for CurlHttpClient if you need to send raw CURLOPT_POSTFIELDS
45
+ private $ body = null ;
43
46
44
47
/**
45
48
* @return HttpRequest
46
49
**/
47
50
public static function create ()
48
51
{
49
- return new self ;
52
+ return new static ();
53
+ }
54
+
55
+ /**
56
+ * @return HttpRequest
57
+ **/
58
+ public static function createFromGlobals ()
59
+ {
60
+ $ request =
61
+ static ::create ()->
62
+ setGet ($ _GET )->
63
+ setPost ($ _POST )->
64
+ setServer ($ _SERVER )->
65
+ setCookie ($ _COOKIE )->
66
+ setFiles ($ _FILES );
67
+
68
+ if (isset ($ _SESSION ))
69
+ $ request ->setSession ($ _SESSION );
70
+
71
+ foreach ($ _SERVER as $ name => $ value )
72
+ if (substr ($ name , 0 , 5 ) === 'HTTP_ ' )
73
+ $ request ->setHeaderVar (substr ($ name , 5 ), $ value );
74
+
75
+ if (
76
+ $ request ->hasServerVar ('CONTENT_TYPE ' )
77
+ && $ request ->getServerVar ('CONTENT_TYPE ' ) !== 'application/x-www-form-urlencoded '
78
+ )
79
+ $ request ->setBody (file_get_contents ('php://input ' ));
80
+
81
+ return $ request ;
50
82
}
51
83
52
84
public function &getGet ()
@@ -138,7 +170,7 @@ public function hasServerVar($name)
138
170
public function setServer (array $ server )
139
171
{
140
172
$ this ->server = $ server ;
141
-
173
+
142
174
return $ this ;
143
175
}
144
176
You can’t perform that action at this time.
0 commit comments