/** * 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; }
/** * Execute the command. * * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $this->output = $output; $this->version = $this->getApplication()->getVersion(); $parser = new VersionParser(); /** * Check for ancilliary options */ if ($input->getOption('rollback')) { $this->rollback(); return; } if ($input->getOption('check')) { $this->printAvailableUpdates(); return; } /** * Update to any specified stability option */ if ($input->getOption('dev')) { $this->updateToDevelopmentBuild(); return; } if ($input->getOption('pre')) { $this->updateToPreReleaseBuild(); return; } if ($input->getOption('stable')) { $this->updateToStableBuild(); return; } if ($input->getOption('non-dev')) { $this->updateToMostRecentNonDevRemote(); return; } /** * If current build is stable, only update to more recent stable * versions if available. User may specify otherwise using options. */ if ($parser->isStable($this->version)) { $this->updateToStableBuild(); return; } /** * By default, update to most recent remote version regardless * of stability. */ $this->updateToMostRecentNonDevRemote(); }
/** * {@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; }
protected function initialize(InputInterface $input, OutputInterface $output) { if ($input->getOption('check') && $input->getOption('rollback')) { throw new \InvalidArgumentException('The --check option is not compatible with --rollback'); } if ($input->getOption('rollback') && ($input->getOption('pre') || $input->getOption('stable'))) { throw new InvalidArgumentException('The --rollback option is not compatible with --pre or --stable'); } if ($input->getOption('pre') && $input->getOption('stable')) { throw new InvalidArgumentException('The --pre and --stable options are mutually exclusive'); } if (!$input->getOption('pre') && !$input->getOption('stable')) { $versionParser = new VersionParser(); $input->setOption('stable', $versionParser->isStable($this->getApplication()->getVersion())); $input->setOption('pre', !$input->getOption('stable')); } }
/** * 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; }
public function testIsDevelopment() { $parser = new VersionParser(); $this->assertFalse($parser->isDevelopment('1.0.0')); $this->assertFalse($parser->isDevelopment('1.0.0b')); $this->assertTrue($parser->isDevelopment('1.0.0-dev')); }
/** * Retrieve the current version available remotely. * * @param Updater $updater * * @return string|bool */ public function getCurrentRemoteVersion(Updater $updater) { $versionParser = new VersionParser(array_keys($this->getAvailableVersions())); 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; }