Created
February 13, 2014 11:48
-
-
Save luniki/8973748 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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