Skip to content

Instantly share code, notes, and snippets.

@luniki
Created February 13, 2014 11:48
Show Gist options
  • Save luniki/8973748 to your computer and use it in GitHub Desktop.
Save luniki/8973748 to your computer and use it in GitHub Desktop.
// copies the HTTP request body from php://input
private static $request_body_stream;
// reads the HTTP request body
// TODO: the body may be too large !!!
private function parseRequestBody($mediaType)
{
if (!isset(self::$request_body_stream)) {
$src = fopen("php://input", "rb");
self::$request_body_stream = tmpfile();
stream_copy_to_stream($src, self::$request_body_stream);
}
rewind(self::$request_body_stream);
$input = stream_get_contents(self::$request_body_stream);
if (isset(self::$mediaTypes[$mediaType])) {
$result = call_user_func(array(__CLASS__, self::$mediaTypes[$mediaType]), $input);
if ($result) {
return $result;
}
}
return $input;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment