File tree Expand file tree Collapse file tree 1 file changed +32
-3
lines changed
Expand file tree Collapse file tree 1 file changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ final class HttpRequest
4646 * @var HttpUrl
4747 */
4848 private $ url = null ;
49-
49+
5050 //for CurlHttpClient if you need to send raw CURLOPT_POSTFIELDS
5151 private $ body = null ;
5252
@@ -55,7 +55,36 @@ final class HttpRequest
5555 **/
5656 public static function create ()
5757 {
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 ;
5988 }
6089
6190 public function &getGet ()
@@ -147,7 +176,7 @@ public function hasServerVar($name)
147176 public function setServer (array $ server )
148177 {
149178 $ this ->server = $ server ;
150-
179+
151180 return $ this ;
152181 }
153182
You can’t perform that action at this time.
0 commit comments