Ejemplo n.º 1
0
 /**
  * Helper function to get the default output format from the current request.
  *
  * @param \RestfulBase $restful_handler
  *   The restful handler for the formatter.
  *
  * @return \RestfulFormatterBase
  *   The formatter plugin to use.
  */
 public static function outputFormat(\RestfulBase $restful_handler = NULL) {
   $restful_handler = $restful_handler ? $restful_handler : restful_get_restful_handler_for_path();
   if ($restful_handler && $formatter_name = $restful_handler->getPluginKey('formatter')) {
     return restful_get_formatter_handler($formatter_name, $restful_handler);
   }
   // Sometimes we will get a default Accept: */* in that case we want to return
   // the default content type and not just any.
   if (!empty($GLOBALS['_SERVER']['HTTP_ACCEPT']) && $GLOBALS['_SERVER']['HTTP_ACCEPT'] != '*/*') {
     foreach (explode(',', $GLOBALS['_SERVER']['HTTP_ACCEPT']) as $accepted_content_type) {
       // Loop through all the formatters and find the first one that matches the
       // Content-Type header.
       foreach (restful_get_formatter_plugins() as $formatter_info) {
         $formatter = restful_get_formatter_handler($formatter_info['name'], $restful_handler);
         if (static::matchContentType($formatter->getContentTypeHeader(), $accepted_content_type)) {
           return $formatter;
         }
       }
     }
   }
   $formatter_name = variable_get('restful_default_output_formatter', 'json');
   return restful_get_formatter_handler($formatter_name, $restful_handler);
 }
Ejemplo n.º 2
0
 /**
  * Returns the names of the available formatter plugins.
  *
  * @return array
  *   Array of formatter names.
  */
 public function formatterNames() {
   $plugin_info = $this->getPlugin();
   if (!empty($plugin_info['formatter'])) {
     // If there is formatter info in the plugin definition, return that.
     return array($plugin_info['formatter']);
   }
   // If there is no formatter info in the plugin definition, return a list
   // of all the formatters available.
   $formatter_names = array();
   foreach (restful_get_formatter_plugins() as $formatter_info) {
     $formatter_names[] = $formatter_info['name'];
   }
   return $formatter_names;
 }