/** * {@inheritdoc} */ public function getCurrentRemoteVersion(Updater $updater) { $versions = array_keys($this->getAvailableVersions()); if (!$this->allowMajor) { $versions = $this->filterByLocalMajorVersion($versions); } $versionParser = new VersionParser($versions); $mostRecent = $versionParser->getMostRecentStable(); // Look for unstable updates if explicitly allowed, or if the local // version is already unstable and there is no new stable version. if ($this->allowUnstable || $versionParser->isUnstable($this->localVersion) && version_compare($mostRecent, $this->localVersion, '<')) { $mostRecent = $versionParser->getMostRecentAll(); } return version_compare($mostRecent, $this->localVersion, '>') ? $mostRecent : false; }
/** * Retrieve the current version available remotely. * * @param Updater $updater * * @return string */ public function getCurrentRemoteVersion(Updater $updater) { /* Switch remote request errors to HttpRequestExceptions */ set_error_handler(array($updater, 'throwHttpRequestException')); $versions = json_decode(humbug_get_contents(self::MANIFEST), true); restore_error_handler(); if (false === $versions) { throw new HttpRequestException(sprintf('Request to URL failed: %s', self::MANIFEST)); } $versionParser = new VersionParser($versions); if ($this->getStability() === self::STABLE) { return $versionParser->getMostRecentStable(); } if ($this->getStability() === self::UNSTABLE) { return $versionParser->getMostRecentUnstable(); } return $versionParser->getMostRecentAll(); }
/** * Detects if new versions are available. * * @return boolean */ protected function newVersionAvailable() { $this->newVersion = $this->strategy->getCurrentRemoteVersion($this); $this->oldVersion = $this->strategy->getCurrentLocalVersion($this); list($new_stability, $new_version) = $this->parseStability($this->newVersion); list($old_stability, $old_version) = $this->parseStability($this->oldVersion); // Release with different stability a newer one. if ($new_stability !== $old_stability) { return true; } list($new_version, $new_offset) = $this->parseOffset($new_version); list($old_version, $old_offset) = $this->parseOffset($old_version); // Release made with larger offset is a newer one. if ($new_version === $old_version) { return $new_offset > $old_offset; } // Just see which version is larger. $version_parser = new VersionParser(array($new_version, $old_version)); return $version_parser->getMostRecentAll() === $new_version; }
/** * Retrieve the current version available remotely. * * @param Updater $updater * @return string|bool */ public function getCurrentRemoteVersion(Updater $updater) { /** Switch remote request errors to HttpRequestExceptions */ set_error_handler(array($updater, 'throwHttpRequestException')); $packageUrl = $this->getApiUrl(); $package = json_decode(humbug_get_contents($packageUrl), true); restore_error_handler(); if (null === $package || json_last_error() !== JSON_ERROR_NONE) { throw new JsonParsingException('Error parsing JSON package data' . (function_exists('json_last_error_msg') ? ': ' . json_last_error_msg() : '')); } $versions = array_keys($package['package']['versions']); $versionParser = new VersionParser($versions); if ($this->getStability() === self::STABLE) { $this->remoteVersion = $versionParser->getMostRecentStable(); } elseif ($this->getStability() === self::UNSTABLE) { $this->remoteVersion = $versionParser->getMostRecentUnstable(); } else { $this->remoteVersion = $versionParser->getMostRecentAll(); } /** * Setup remote URL if there's an actual version to download */ if (!empty($this->remoteVersion)) { $this->remoteUrl = $this->getDownloadUrl($package); } return $this->remoteVersion; }
public function testShouldSelectMostRecentIgnoringStabilityExceptDevFromPrefixedSelection() { $versions = array('v1.0.0b', 'v1.0.1', 'v1.1.0a', 'v1.2.0-dev'); $parser = new VersionParser($versions); $this->assertSame('v1.1.0a', $parser->getMostRecentAll()); }
/** * Retrieve the current version available remotely. * * @param Updater $updater * * @return string|bool * A version number or false if no versions were found. */ public function getCurrentRemoteVersion(Updater $updater) { $versionParser = new VersionParser(array_keys($this->getAvailableVersions())); if ($this->allowUnstable) { return $versionParser->getMostRecentAll(); } return $versionParser->getMostRecentStable(); }
/** * Installs puli to the current working directory. * * @return int The return status. * * @throws Exception */ private function installPuli() { $workingDir = str_replace('\\', '/', getcwd()); $installDir = is_dir($this->installDir) ? realpath($this->installDir) : $workingDir; $installPath = str_replace('\\', '/', $installDir) . '/' . $this->filename; $shortInstallPath = $installPath; // Strip the current working directory if possible if (0 === strpos($shortInstallPath, $workingDir . '/')) { $shortInstallPath = substr($shortInstallPath, strlen($workingDir . '/')); } if (is_readable($installPath)) { @unlink($installPath); } $httpClient = new HttpClient(); $versions = array(); for ($retries = 3; $retries > 0; --$retries) { if (!$this->quiet) { $this->info('Downloading available versions...'); } try { $versions = $this->downloadVersions($httpClient, static::VERSION_API_URL); break; } catch (RuntimeException $e) { $this->error($e->getMessage()); } } if (0 === $retries || empty($versions)) { $this->error('fatal: The download failed repeatedly, aborting.'); return 1; } $versionParser = new VersionParser($versions); if (!empty($this->version)) { if (!in_array($this->version, $versions, true)) { $this->error(sprintf('fatal: Could not find version: %s.', $this->version)); return 1; } } elseif ('stable' === $this->stability) { $this->version = $versionParser->getMostRecentStable(); if (false === $this->version) { $this->error('fatal: Could not find a stable version.'); return 1; } } else { $this->version = $versionParser->getMostRecentAll(); } $url = sprintf(static::PHAR_DOWNLOAD_URL, $this->version); for ($retries = 3; $retries > 0; --$retries) { if (!$this->quiet) { $this->info(sprintf('Downloading puli.phar at version %s...', $this->version)); } if (!$this->downloadFile($httpClient, $url, $installPath)) { continue; } try { $this->validatePhar($installPath); } catch (Exception $e) { unlink($installPath); if (!$e instanceof UnexpectedValueException && !$e instanceof PharException) { throw $e; } if ($retries > 0) { if (!$this->quiet) { $this->error('The download is corrupt, retrying...'); } } else { $this->error(sprintf('fatal: The download is corrupt (%s), aborting.', $e->getMessage())); return 1; } } break; } if (0 === $retries) { $this->error('fatal: The download failed repeatedly, aborting.'); return 1; } chmod($installPath, 0755); if (!$this->quiet) { $this->success(PHP_EOL . 'Puli successfully installed to: ' . $installPath); $this->info('Use it: php ' . $shortInstallPath); } return 0; }