Skip to content

Instantly share code, notes, and snippets.

@kitsunet
Created June 6, 2014 19:54
Show Gist options
  • Select an option

  • Save kitsunet/a496d3423221f44bc91d to your computer and use it in GitHub Desktop.

Select an option

Save kitsunet/a496d3423221f44bc91d to your computer and use it in GitHub Desktop.
protected function decodeBodyArguments($body, $mediaType) {
switch (MediaTypes::trimMediaType($mediaType)) {
case 'application/json':
case 'application/x-javascript':
case 'text/javascript':
case 'text/x-javascript':
case 'text/x-json':
$arguments = array();
$decoded_json_body = json_decode($body, TRUE);
if ($decoded_json_body !== NULL) {
$arguments['decoded_json_body'] = $decoded_json_body;
}
break;
case 'text/xml':
case 'application/xml':
try {
$xmlElement = new \SimpleXMLElement(urldecode($body), LIBXML_NOERROR);
} catch (\Exception $e) {
return array();
}
$arguments = Arrays::convertObjectToArray($xmlElement);
break;
case 'application/x-www-form-urlencoded':
default:
parse_str($body, $arguments);
break;
}
return $arguments;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment