You are here

protected static function Request::parseBodyContentType in RESTful 7.2

Parses the provided payload according to a content type.

Parameters

string $content_type: The contents of the Content-Type header.

Return value

array The parsed body.

Throws

\Drupal\restful\Exception\BadRequestException

1 call to Request::parseBodyContentType()
Request::parseBody in src/Http/Request.php
Parses the body.

File

src/Http/Request.php, line 321
Contains \Drupal\restful\Http\Request

Class

Request
Deals with everything coming from the consumer.

Namespace

Drupal\restful\Http

Code

protected static function parseBodyContentType($content_type) {
  if (!($input_string = file_get_contents('php://input'))) {
    return NULL;
  }
  if ($content_type == 'application/x-www-form-urlencoded') {
    $body = NULL;
    parse_str($input_string, $body);
    return $body;
  }

  // Use the Content Type header to negotiate a formatter to parse the body.
  $formatter = restful()
    ->getFormatterManager()
    ->negotiateFormatter($content_type);
  return $formatter
    ->parseBody($input_string);
}