1 common.inc _backdrop_version_compare_convert($version_string)

Converts a Backdrop version string into numeric-only version string.

Parameters

string $version_string: A version string such as 1.10.0-beta4 or 1.4.x-dev.

Return value

string: A converted string only containing numbers, for use in PHP's version_compare() function.

File

core/includes/common.inc, line 8591
Common functions that many Backdrop modules will need to reference.

Code

function _backdrop_version_compare_convert($version_string) {
  // Convert "dev" releases to be the highest possible version number. For
  // example 1.5.x-dev should be considered higher than any other 1.5 release,
  // so we replace .x with 99999.
  $version_string = str_replace('.x-dev', '.99999', $version_string);

  // Replace common indicators with numeric equivalents for version_compare().
  $indicator_order = array(
    1 => 'alpha',
    2 => 'beta',
    3 => 'preview',
    4 => 'rc',
  );
  foreach ($indicator_order as $order => $indicator) {
    // Replace both before and after the indicator with dots, so that multiple
    // alphas, betas, etc. would be ordered properly. For example, version
    // 1.5.0-beta9 and 1.5.0-beta10 would become 1.5.0.2.9 and 1.5.0.2.10.
    $version_string = str_replace('-' . $indicator, '.' . $order . '.', $version_string);
    $version_string .= substr($version_string, -1) === '.' ? '0' : '';
  }
  return $version_string;
}