/**
  * Checks the remote version file against the local version file.
  *
  * @return string
  */
 public function check()
 {
     //Parse local version file
     $versionFile = base_path('version.json');
     if (!file_exists($versionFile)) {
         return view('self-updater::error')->with('error', 'No version file found.');
     }
     $localVersionFile = file_get_contents(base_path('version.json'));
     $localVersionJson = json_decode($localVersionFile, true);
     //Parse remote version file
     $remoteVersionFile = @file_get_contents(config('self-updater.remote_uri') . '/remote_version.json');
     if ($remoteVersionFile === false) {
         return view('self-updater::error')->with('error', 'Can not read remote version file.');
     }
     $remoteVersionJson = json_decode($remoteVersionFile, true);
     $remoteVersion = $remoteVersionJson['version'];
     $localVersion = $localVersionJson['version'];
     $newVersion = Compare::greaterThan(Parser::parse($remoteVersion), Parser::parse($localVersion));
     return view('self-updater::checker', compact('localVersion', 'remoteVersion', 'newVersion'));
 }
 private function greaterOrEqual($givenAppVersion, $pluginMinAppVersion)
 {
     try {
         $givenAppVersionSem = Parser::parse($givenAppVersion);
         $pluginMinAppVersionSem = Parser::parse($pluginMinAppVersion);
         return Compare::greaterThan($givenAppVersionSem, $pluginMinAppVersionSem) || Compare::equals($givenAppVersionSem, $pluginMinAppVersionSem);
     } catch (\Exception $e) {
         return false;
     }
 }
示例#3
0
 /**
  * Assert that of two version strings the first is bigger than the other
  *
  * @return void
  **/
 private function assertVersionBiggerThan($v1String, $v2String)
 {
     // Parse them
     $v1 = Parser::parse($v1String);
     $v2 = Parser::parse($v2String);
     // Versions should not be equal
     $this->assertFalse(Compare::equals($v1, $v2), 'Version "' . $v1 . '" should *not* be equal to "' . $v2 . '"');
     // Greater than and not greater than
     $this->assertTrue(Compare::greaterThan($v1, $v2), 'Version "' . $v1 . '" should be greater than "' . $v2 . '"');
     $this->assertFalse(Compare::greaterThan($v2, $v1), 'Version "' . $v2 . '" should be greater than "' . $v1 . '"');
     // Smaller than and not smaller than
     $this->assertTrue(Compare::smallerThan($v2, $v1), 'Version "' . $v2 . '" should be smaller than "' . $v1 . '"');
     $this->assertFalse(Compare::smallerThan($v1, $v2), 'Version "' . $v1 . '" should *not* be smaller than "' . $v2 . '"');
 }
示例#4
0
文件: Version.php 项目: naneau/semver
 /**
  * Get the next logical version relative to the provided base version. If
  * no base is supplied, base will be the same as the current version.
  *
  * @param  Version|string|null $base
  * @return Version
  * @throws InvalidArgumentException
  */
 public function next($base = null)
 {
     //  Ensure that $base is a Version. Parse it if we must, use ourself if
     //  it is empty.
     if (empty($base)) {
         $base = $this;
     } else {
         if (is_string($base)) {
             $base = Parser::parse($base);
         } elseif (!$base instanceof Version) {
             throw new InvalidArgumentException("\$base must be of type Version");
         }
     }
     // If the base is ahead of this Version then the next version will be
     // the base.
     if (Compare::greaterThan($base, $this)) {
         return $base->cleanCopy();
     }
     $next = new Version();
     $next->setMajor($this->getMajor());
     $next->setMinor($this->getMinor());
     $next->setPatch($this->getPatch());
     if ($base->hasPreRelease()) {
         if ($this->hasPreRelease()) {
             // We already know that $base is less than or equal to $this
             // and we won't be jumping to the next greek value. So it is
             // safe use $this prerelease and just increment the release
             // number.
             $pre = new PreRelease();
             $pre->setGreek($this->getPreRelease()->getGreek());
             $pre->setReleaseNumber($this->getPreRelease()->getReleaseNumber() + 1);
             $next->setPreRelease($pre);
         } else {
             throw new InvalidArgumentException("This version has left prerelease without updating the base. Base should not be prerelease.");
         }
     } elseif (!$this->hasPreRelease()) {
         $next->setPatch($this->getPatch() + 1);
     }
     // The case of $this having a pre-release when $base does not means
     // that we are essentially just leaving pre-release. Nothing needs to
     // be done.
     return $next;
 }
示例#5
0
 /**
  * Sort an array of Versions
  *
  * unlike sort() this method accepts only an array of Version instances
  *
  * This method uses QuickSort for the actual sorting
  *
  * @param array[int]Version
  * @return array[int]Version
  **/
 public static function sortArray(array $versions)
 {
     // Empty array does not needs sorting
     if (count($versions) === 0) {
         return array();
     }
     // Array of one item (pivot) from the middle
     $pivotArray = array_splice($versions, (int) floor((count($versions) - 1) / 2), 1);
     // Smaller/greater than pivot stack
     $smaller = array();
     $greater = array();
     // Fill stacks
     foreach ($versions as $version) {
         if (Compare::greaterThan($version, $pivotArray[0])) {
             $greater[] = $version;
         } else {
             $smaller[] = $version;
         }
     }
     // Recurse and merge results
     return array_merge(self::sortArray($smaller), $pivotArray, self::sortArray($greater));
 }