Esempio n. 1
0
 function testNegativeRange()
 {
     $compare = array(array("1.0.0 - 2.0.0", "2.2.3"), array("1.0.0", "1.0.1"), array(">=1.0.0", "0.0.0"), array(">=1.0.0", "0.0.1"), array(">=1.0.0", "0.1.0"), array(">1.0.0", "0.0.1"), array(">1.0.0", "0.1.0"), array("<=2.0.0", "3.0.0"), array("<=2.0.0", "2.9999.9999"), array("<=2.0.0", "2.2.9"), array("<2.0.0", "2.9999.9999"), array("<2.0.0", "2.2.9"), array(">=0.1.97", "v0.1.93"), array(">=0.1.97", "0.1.93"), array("0.1.20 || 1.2.4", "1.2.3"), array(">=0.2.3 || <0.0.1", "0.0.3"), array(">=0.2.3 || <0.0.1", "0.2.2"), array("2.x.x", "1.1.3"), array("2.x.x", "3.1.3"), array("1.2.x", "1.3.3"), array("1.2.x || 2.x", "3.1.3"), array("1.2.x || 2.x", "1.1.3"), array("2.*.*", "1.1.3"), array("2.*.*", "3.1.3"), array("1.2.*", "1.3.3"), array("1.2.* || 2.*", "3.1.3"), array("1.2.* || 2.*", "1.1.3"), array("2", "1.1.2"), array("2.3", "2.4.1"), array("~2.4", "2.5.0"), array("~2.4", "2.3.9"), array("~>3.2.1", "3.3.2"), array("~>3.2.1", "3.2.0"), array("~1", "0.2.3"), array("~>1", "2.2.3"), array("~1.0", "1.1.0"), array("<1", "1.0.0"), array(">=1.2", "1.1.1"), array("<1", "1.0.0beta"), array("< 1", "1.0.0beta"), array("1", "2.0.0beta"), array(">1.0.0", "1.0.0beta"), array("~v0.5.4-beta", "0.5.4-alpha"), array('=0.7.x', '0.8.2'), array('>=0.7.x', '0.6.2'), array('<=0.7.x', '0.7.2'));
     foreach ($compare as $set) {
         $v = new SemVer\version($set[1]);
         $this->assertFalse($v->satisfies(new SemVer\expression($set[0])), "%s > {$set['0']} should not be satisfied by {$set['1']}");
     }
 }
Esempio n. 2
0
 /**
  * Check requirements
  * @param array $requires The array containing the requirements
  * @param bool $boolean Whether the return value must be a boolean
  * @param bool $multi Whether return value contain both satisfy boolean and requirement version
  */
 public static function checkRequirements($requires, $boolean = false, $multi = false)
 {
     $result = $requires;
     /**
      * $requiredVersion will look like ">=5.0"
      */
     foreach ($requires as $dependency => $requiredVersion) {
         $currentVersion = self::getDependencyVersion($dependency);
         /**
          * Compare the current version and required version
          */
         $version = new version($currentVersion);
         if ($version->satisfies(new expression($requiredVersion))) {
             $result[$dependency] = true;
         } else {
             $result[$dependency] = false;
         }
         /**
          * If dependency is an app
          */
         if (strpos($dependency, "/") !== false) {
             list($mainDependency, $subDependency) = explode("/", $dependency);
             if ($mainDependency === "app") {
                 $App = new Apps($subDependency);
                 if ($multi) {
                     $result = $result + self::checkRequirements($App->info["require"], false, true);
                 } else {
                     if ($boolean) {
                         $result[$dependency] = self::checkRequirements($App->info["require"], true);
                     } else {
                         $result = $result + self::checkRequirements($App->info["require"]);
                     }
                 }
             }
         }
     }
     if ($multi) {
         foreach ($result as $dependency => $satisfy) {
             if (!is_array($satisfy)) {
                 $result[$dependency] = array("require" => $requires[$dependency], "satisfy" => $satisfy);
             }
         }
         return $result;
     }
     return $boolean ? !in_array(false, $result) : $result;
 }
Esempio n. 3
0
 public function checkVersions($versionList, $currentVersion, $errorMessage = '')
 {
     if (empty($versionList)) {
         return true;
     }
     if (is_string($versionList)) {
         $versionList = (array) $versionList;
     }
     try {
         $semver = new SemVer\version($currentVersion);
     } catch (\Exception $e) {
         $GLOBALS['log']->error('Cannot recognize currentVersion [' . $currentVersion . '], error: ' . $e->getMessage() . '.');
         return false;
     }
     foreach ($versionList as $version) {
         $isInRange = false;
         try {
             $isInRange = $semver->satisfies(new SemVer\expression($version));
         } catch (\Exception $e) {
             $GLOBALS['log']->error('Version identification error: ' . $e->getMessage() . '.');
         }
         if ($isInRange) {
             return true;
         }
     }
     $this->throwErrorAndRemovePackage($errorMessage);
 }
 /**
  * Checks if a plugin version is matches.
  *
  * @param  array $config
  * @return bool
  */
 public function pluginMatches($config)
 {
     $constraint = array_get($config, 'constraint', self::VERSION);
     return $this->version->satisfies(new SemVersionExpression($constraint));
 }
Esempio n. 5
0
 public function getVersionsToSync()
 {
     $versionsToSync = [];
     $currentVersions = $this->project->getRefs();
     $allowedVersionRange = new expression($this->setting('sync.sync.versions'));
     $tags = $this->github->repositories()->tags($this->setting('owner'), $this->setting('repository'));
     foreach ($tags as $tag) {
         try {
             $version = new version($tag['name']);
         } catch (SemVerException $e) {
             continue;
         }
         if ($version->satisfies($allowedVersionRange) === false or in_array($version->getVersion(), $currentVersions, true)) {
             continue;
         }
         $versionsToSync[] = $version;
     }
     return $versionsToSync;
 }
Esempio n. 6
0
 public function getVersionsToSync()
 {
     $versionsToSync = [];
     $remote = $this->client($this->setting('remote'));
     $currentVersions = $this->project->getRefs();
     $allowedVersionRange = new expression($this->setting('sync.constraints.versions'));
     $tags = $remote->getTags($this->setting('repository'), $this->setting('owner'));
     #$this->remote->repositories()->tags();
     $this->fire('git.syncer.versions.start', [$tags]);
     foreach ($tags as $tag => $sha) {
         try {
             $version = new version($tag);
         } catch (SemVerException $e) {
             continue;
         }
         if ($version->satisfies($allowedVersionRange) === false or in_array($version->getVersion(), $currentVersions, true)) {
             continue;
         }
         $versionsToSync[] = $version;
     }
     $this->fire('git.syncer.versions.finish', [$versionsToSync]);
     return $versionsToSync;
 }