You are here

public function ResourceManager::getVersionFromRequest in RESTful 7.2

Gets the major and minor version for the current request.

Return value

array The array with the version.

Overrides ResourceManagerInterface::getVersionFromRequest

1 call to ResourceManager::getVersionFromRequest()
ResourceManager::negotiate in src/Resource/ResourceManager.php
Gets the resource plugin based on the information in the request object.

File

src/Resource/ResourceManager.php, line 137
Contains \Drupal\restful\Resource\ResourceManager.

Class

ResourceManager

Namespace

Drupal\restful\Resource

Code

public function getVersionFromRequest() {
  $version =& drupal_static(__METHOD__);
  if (isset($version)) {
    return $version;
  }
  $path = $this->request
    ->getPath(FALSE);
  list($resource_name, $version) = static::getPageArguments($path);
  if (preg_match('/^v\\d+(\\.\\d+)?$/', $version)) {
    $version = $this
      ->parseVersionString($version, $resource_name);
    return $version;
  }

  // If there is no version in the URL check the header.
  if ($version_string = $this->request
    ->getHeaders()
    ->get('x-api-version')
    ->getValueString()) {
    $version = $this
      ->parseVersionString($version_string, $resource_name);
    return $version;
  }

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