protected function RESTServer::parseRequestBody in Services 7.3
Parse request body based on $_SERVER['CONTENT_TYPE'].s
Return value
array|mixed
2 calls to RESTServer::parseRequestBody()
- MockRESTServer::protectedParseRequestBody in servers/
rest_server/ tests/ rest_server_mock_classes.inc - RESTServer::getControllerArguments in servers/
rest_server/ includes/ RESTServer.inc - Parses controller arguments from request
File
- servers/
rest_server/ includes/ RESTServer.inc, line 376 - Class for handling REST calls.
Class
- RESTServer
- @file Class for handling REST calls.
Code
protected function parseRequestBody() {
$method = $this
->getRequestMethod();
switch ($method) {
case 'POST':
case 'PUT':
$server_content_type = $this->context
->getServerVariable('CONTENT_TYPE');
if (!empty($server_content_type)) {
$type = $this
->parseContentHeader($server_content_type);
}
// Get the mime type for the request, default to form-urlencoded
if (isset($type['value'])) {
$mime = $type['value'];
}
else {
$mime = 'application/x-www-form-urlencoded';
}
// Get the parser for the mime type
$parser = $this
->matchParser($mime, $this->parsers);
if (!$parser) {
return services_error(t('Unsupported request content type @mime', array(
'@mime' => $mime,
)), 406);
}
$data = array();
if (class_exists($parser) && in_array('ServicesParserInterface', class_implements($parser))) {
$parser_object = new $parser();
$data = $parser_object
->parse($this->context);
}
return $data;
default:
return array();
}
}