You are here

function hosting_package_instance_version_code in Hosting 7.4

Same name and namespace in other branches
  1. 6.2 package/hosting_package.instance.inc \hosting_package_instance_version_code()
  2. 7.3 package/hosting_package.instance.inc \hosting_package_instance_version_code()

Turn package version string into a number

This function returns a float value for the number that represents the version string.

2 calls to hosting_package_instance_version_code()
hosting_package_instance_sync in package/hosting_package.instance.inc
Generate instances to reference nodes to releases.
hosting_package_update_9 in package/hosting_package.install
Implements hook_update_N().

File

package/hosting_package.instance.inc, line 283
API for mapping packages to various Hosting node types

Code

function hosting_package_instance_version_code($version) {
  $defaults = array(
    'platform_major' => 0,
    'platform_minor' => 0,
    'package_major' => 0,
    'package_minor' => 0,
    'package_version_type' => 'release',
    'package_patch_level' => 0,
  );
  $release_types = array(
    '' => 0,
    'dev' => 0,
    'unstable' => 1,
    'alpha' => 2,
    'beta' => 3,
    'rc' => 4,
    'release' => 5,
  );
  $regex = array(
    'core' => '/^(?P<platform_major>\\d?)\\.(?P<platform_minor>[x\\d]*)?(-(?P<package_version_type>dev|unstable|alpha|beta|rc)?(?P<package_patch_level>\\d)*)?$/',
    'contrib' => "/(?P<platform_major>\\d?)\\.(?P<platform_minor>[x\\d]*)?(-(?P<package_major>\\d*)?\\.(?P<package_minor>[x\\d]*)?(-(?P<package_version_type>alpha|unstable|beta|rc|dev)?(?P<package_patch_level>[\\d]*)?)?)?/",
  );
  $matches = array();
  if (preg_match($regex['core'], $version, $matches)) {
    $matches = array_merge($defaults, $matches);
  }
  elseif (preg_match($regex['contrib'], $version, $matches)) {
    $matches = array_merge($defaults, $matches);
  }
  else {
    return 0;
  }

  // we use the float type because php generally has a maximum integer value to small to handle this value
  $result = (double) sprintf("%d%02d%02d%02d%02d%02d", $matches['platform_major'], $matches['platform_minor'], $matches['package_major'], $matches['package_minor'], $release_types[$matches['package_version_type']], $matches['package_patch_level']);
  return $result;
}