You are here

protected function RESTServer::getResponseFormatter in Services 7.3

Response formatter is responsible for encoding the response.

Return value

array example: array( 'xml' => array( 'mime types' => array('application/xml', 'text/xml'), 'formatter class' => 'ServicesXMLFormatter', ), )

2 calls to RESTServer::getResponseFormatter()
MockRESTServer::protectedGetResponseFormatter in servers/rest_server/tests/rest_server_mock_classes.inc
RESTServer::handle in servers/rest_server/includes/RESTServer.inc
Handles the call to the REST server

File

servers/rest_server/includes/RESTServer.inc, line 182
Class for handling REST calls.

Class

RESTServer
@file Class for handling REST calls.

Code

protected function getResponseFormatter() {
  $mime_type = '';
  $canonical_path_not_parsed = $this->context
    ->getCanonicalPath();
  $response_format = $this
    ->getResponseFormatFromURL($canonical_path_not_parsed);
  if (empty($response_format)) {
    $response_format = $this
      ->getResponseFormatContentTypeNegotiations($mime_type, $canonical_path_not_parsed, $this->formatters);
  }
  $formatter = array();
  if (isset($this->formatters[$response_format])) {
    $formatter = $this->formatters[$response_format];
  }

  // Check if we support the response format and determine the mime type
  if (empty($mime_type) && !empty($formatter)) {
    $mime_type = $formatter['mime types'][0];
  }
  if (empty($response_format) || empty($mime_type)) {
    return services_error(t('Unknown or unsupported response format.'), 406);
  }

  // Set the content type and render output.
  drupal_add_http_header('Content-type', $mime_type);
  return $formatter;
}