function _pm_parse_version_decompound

8.0.x pm.drush.inc _pm_parse_version_decompound($version)
7.x pm.drush.inc _pm_parse_version_decompound($version)
master pm.drush.inc _pm_parse_version_decompound($version)

Decompound a version string and returns major, minor, patch and extra parts.

Parameters

string $version: A version string like X.Y-Z, X.Y.Z-W or a subset.

Return value

array Array with major, patch and extra keys.

See also

_pm_parse_version_compound()

pm_parse_version()

1 call to _pm_parse_version_decompound()
pm_parse_version in commands/pm/pm.drush.inc
Parses a version string and returns its components.

File

commands/pm/pm.drush.inc, line 1440
The drush Project Manager

Code

function _pm_parse_version_decompound($version) {
  $pattern = '/^(\d+)(?:.(\d+))?(?:\.(x|\d+))?(?:-([a-z0-9\.-]*))?(?:\+(\d+)-dev)?$/';

  $matches = array();
  preg_match($pattern, $version, $matches);

  $parts = array(
    'major' => '',
    'minor' => '',
    'patch' => '',
    'extra' => '',
    'offset' => '',
  );
  if (isset($matches[1])) {
    $parts['major'] = $matches[1];
    if (isset($matches[2])) {
      if (isset($matches[3]) && $matches[3] != '') {
        $parts['minor'] = $matches[2];
        $parts['patch'] = $matches[3];
      }
      else {
        $parts['patch'] = $matches[2];
      }
    }
    if (!empty($matches[4])) {
      $parts['extra'] = $matches[4];
    }
    if (!empty($matches[5])) {
      $parts['offset'] = $matches[5];
    }
  }

  return $parts;
}