Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions main/Flow/HttpRequest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final class HttpRequest
* @var HttpUrl
*/
private $url = null;

//for CurlHttpClient if you need to send raw CURLOPT_POSTFIELDS
private $body = null;

Expand All @@ -55,7 +55,36 @@ final class HttpRequest
**/
public static function create()
{
return new self;
return new static();
}

/**
* @return HttpRequest
**/
public static function createFromGlobals()
{
$request =
static::create()->
setGet($_GET)->
setPost($_POST)->
setServer($_SERVER)->
setCookie($_COOKIE)->
setFiles($_FILES);

if (isset($_SESSION))
$request->setSession($_SESSION);

foreach ($_SERVER as $name => $value)
if (substr($name, 0, 5) === 'HTTP_')
$request->setHeaderVar(substr($name, 5), $value);

if (
$request->hasServerVar('CONTENT_TYPE')
&& $request->getServerVar('CONTENT_TYPE') !== 'application/x-www-form-urlencoded'
)
$request->setBody(file_get_contents('php://input'));

return $request;
}

public function &getGet()
Expand Down Expand Up @@ -147,7 +176,7 @@ public function hasServerVar($name)
public function setServer(array $server)
{
$this->server = $server;

return $this;
}

Expand Down