Added method to get the request body.

pull/126/head
Mike Cao 11 years ago
parent 0f49cc7abc
commit ab2aba4e7d

@ -1 +1 @@
1.1.8 1.1.9

@ -146,7 +146,7 @@ class Request {
'ajax' => self::getVar('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest', 'ajax' => self::getVar('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest',
'scheme' => self::getVar('SERVER_PROTOCOL', 'HTTP/1.1'), 'scheme' => self::getVar('SERVER_PROTOCOL', 'HTTP/1.1'),
'user_agent' => self::getVar('HTTP_USER_AGENT'), 'user_agent' => self::getVar('HTTP_USER_AGENT'),
'body' => file_get_contents('php://input'), 'body' => self::getBody(),
'type' => self::getVar('CONTENT_TYPE'), 'type' => self::getVar('CONTENT_TYPE'),
'length' => self::getVar('CONTENT_LENGTH', 0), 'length' => self::getVar('CONTENT_LENGTH', 0),
'query' => new Collection($_GET), 'query' => new Collection($_GET),
@ -197,20 +197,19 @@ class Request {
} }
/** /**
* Parse query parameters from a URL. * Gets the body of the request.
* *
* @param string $url URL string * @return string Raw HTTP request body
* @return array Query parameters
*/ */
public static function parseQuery($url) { public static function getBody()
$params = array(); {
$method = self::getVar('REQUEST_METHOD', 'GET');
$args = parse_url($url); if ($method == 'POST' || $method == 'PUT') {
if (isset($args['query'])) { return file_get_contents('php://input');
parse_str($args['query'], $params);
} }
return $params; return '';
} }
/** /**
@ -268,4 +267,21 @@ class Request {
public static function getVar($var, $default = '') { public static function getVar($var, $default = '') {
return isset($_SERVER[$var]) ? $_SERVER[$var] : $default; return isset($_SERVER[$var]) ? $_SERVER[$var] : $default;
} }
/**
* Parse query parameters from a URL.
*
* @param string $url URL string
* @return array Query parameters
*/
public static function parseQuery($url) {
$params = array();
$args = parse_url($url);
if (isset($args['query'])) {
parse_str($args['query'], $params);
}
return $params;
}
} }

Loading…
Cancel
Save