You are here

protected function ResourceManager::parseVersionString in RESTful 7.2

Parses the version string.

Parameters

string $version: The string containing the version information.

string $resource_name: (optional) Name of the resource to get the latest minor version.

Return value

array Numeric array with major and minor version.

1 call to ResourceManager::parseVersionString()
ResourceManager::getVersionFromRequest in src/Resource/ResourceManager.php
Gets the major and minor version for the current request.

File

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

Class

ResourceManager

Namespace

Drupal\restful\Resource

Code

protected function parseVersionString($version, $resource_name = NULL) {
  if (preg_match('/^v\\d+(\\.\\d+)?$/', $version)) {

    // Remove the leading 'v'.
    $version = substr($version, 1);
  }
  $output = explode('.', $version);
  if (count($output) == 1) {
    $major_version = $output[0];

    // Abort if the version is not numeric.
    if (!$resource_name || !ctype_digit((string) $major_version)) {
      return NULL;
    }

    // Get the latest version for the resource.
    return $this
      ->getResourceLastVersion($resource_name, $major_version);
  }

  // Abort if any of the versions is not numeric.
  if (!ctype_digit((string) $output[0]) || !ctype_digit((string) $output[1])) {
    return NULL;
  }
  return $output;
}