/**
  * Compares two versions and returns 0 if $a == $b, -1 if $a < $b and +1 if $b > $a.
  *
  * @param AddonVersion
  * @param AddonVersion
  * @return int
  */
 public function compare(AddonVersion $a, AddonVersion $b)
 {
     $parser = $this->getParser();
     $a = $parser->normalize($a->version);
     $b = $parser->normalize($b->version);
     $constraint = new VersionConstraint(NULL, NULL);
     if ($constraint->versionCompare($a, $b, '==')) {
         return 0;
     } elseif ($constraint->versionCompare($a, $b, '<')) {
         return -1;
     } else {
         return 1;
     }
 }
 /**
  * Check version requirements from the "extra" block of a package
  * against the local Roundcube version
  */
 private function rcubeVersionCheck($package)
 {
     $parser = new VersionParser();
     // read rcube version from iniset
     $rootdir = getcwd();
     $iniset = @file_get_contents($rootdir . '/program/include/iniset.php');
     if (preg_match('/define\\(.RCMAIL_VERSION.,\\s*.([0-9.]+[a-z-]*)?/', $iniset, $m)) {
         $rcubeVersion = $parser->normalize(str_replace('-git', '.999', $m[1]));
     } else {
         throw new \Exception("Unable to find a Roundcube installation in {$rootdir}");
     }
     $extra = $package->getExtra();
     if (!empty($extra['roundcube'])) {
         foreach (array('min-version' => '>=', 'max-version' => '<=') as $key => $operator) {
             if (!empty($extra['roundcube'][$key])) {
                 $version = $parser->normalize(str_replace('-git', '.999', $extra['roundcube'][$key]));
                 $constraint = new VersionConstraint($operator, $version);
                 if (!$constraint->versionCompare($rcubeVersion, $version, $operator)) {
                     throw new \Exception("Version check failed! " . $package->getName() . " requires Roundcube version {$operator} {$version}, {$rcubeVersion} was detected.");
                 }
             }
         }
     }
 }
示例#3
0
 public function compareVersion($a, $b)
 {
     $constraint = new VersionConstraint('>', '');
     return $constraint->versionCompare($this->parser->normalize($a['version']), $this->parser->normalize($b['version']), '<', true);
 }