You are here

public static function RestfulBase::getVersionFromRequest in RESTful 7

Gets the major and minor version for the current request.

Parameters

string $path: The router path.

Return value

array The array with the version.

3 calls to RestfulBase::getVersionFromRequest()
restful_get_restful_handler_for_path in ./restful.module
Helper function to get the restful handler for the selected path.
restful_menu_access_callback in ./restful.module
Access callback; Determine access for an API call.
restful_menu_process_callback in ./restful.module
Page callback; Return the response for an API call.

File

plugins/restful/RestfulBase.php, line 1504
Contains RestfulBase.

Class

RestfulBase
Class \RestfulBase

Code

public static function getVersionFromRequest($path = NULL) {
  $version =& drupal_static(__CLASS__ . '::' . __FUNCTION__);
  if (isset($version)) {
    return $version;
  }
  list($resource_name, $version) = static::getPageArguments($path);
  if (preg_match('/^v\\d+(\\.\\d+)?$/', $version)) {
    $version = static::parseVersionString($version, $resource_name);
    return $version;
  }

  // If there is no version in the URL check the header.
  if ($api_version = \RestfulManager::getRequestHttpHeader('X-API-Version')) {
    $version = static::parseVersionString($api_version, $resource_name);
    return $version;
  }

  // If there is no version negotiation information return the latest version.
  $version = static::getResourceLastVersion($resource_name);
  return $version;
}