public static getInstance ( CLIFramework\Logger $logger, |
||
$logger | CLIFramework\Logger | |
$options | ||
$downloader | string | |
return |
protected function getPackageXml($packageName, $version) { $channel = new PeclChannel($this->site); $baseUrl = $channel->getRestBaseUrl(); $url = "{$baseUrl}/r/" . strtolower($packageName); $downloader = new CurlDownloader(); $downloader = DownloadFactory::getInstance($this->logger, $this->options); // translate version name into numbers if (in_array($version, array('stable', 'latest', 'beta'))) { $stabilityTxtUrl = $url . '/' . $version . '.txt'; if ($ret = $downloader->request($stabilityTxtUrl)) { $version = (string) $ret; } else { throw new Exception("Can not translate stability {$version} into exact version name."); } } $xmlUrl = $url . '/' . $version . '.xml'; if ($ret = $downloader->request($xmlUrl)) { $dom = new DOMDocument('1.0'); $dom->strictErrorChecking = false; $dom->preserveWhiteSpace = false; // $dom->resolveExternals = false; if (false === $dom->loadXml($ret)) { throw new Exception("Error in XMl document: {$url}"); } return $dom; } return false; }
public function download($url, $dir, $md5 = null) { if (!is_writable($dir)) { throw new Exception("Directory is not writable: {$dir}"); } $downloader = DownloadFactory::getInstance($this->logger, $this->options); $basename = $downloader->resolveDownloadFileName($url); if (!$basename) { throw new Exception("Can not parse url: {$url}"); } $targetFilePath = $dir . DIRECTORY_SEPARATOR . $basename; if (!$this->options->force && file_exists($targetFilePath)) { $this->logger->info('Checking distribution checksum...'); $md5a = md5_file($targetFilePath); if ($md5 && $md5a != $md5) { $this->logger->warn("Checksum mismatch: {$md5a} != {$md5}"); $this->logger->info('Re-Downloading...'); $downloader->download($url, $targetFilePath); } else { $this->logger->info('Checksum matched: ' . $md5); } } else { $downloader->download($url, $targetFilePath); } return $targetFilePath; }
public function execute($branch = 'master') { global $argv; $script = realpath($argv[0]); if (!is_writable($script)) { throw new Exception("{$script} is not writable."); } // fetch new version phpbrew $this->logger->info("Updating phpbrew {$script} from {$branch}..."); $url = "https://raw.githubusercontent.com/phpbrew/phpbrew/{$branch}/phpbrew"; //download to a tmp file first $downloader = DownloadFactory::getInstance($this->logger, $this->options, array(DownloadFactory::METHOD_CURL, DownloadFactory::METHOD_WGET)); //the phar file is large so we prefer the commands rather than extensions. $tempFile = $downloader->download($url); if ($tempFile === false) { throw new RuntimeException('Update Failed', 1); } chmod($tempFile, 0755); //todo we can check the hash here in order to make sure we have download the phar successfully //move the tmp file to executable path $code = rename($tempFile, $script); if ($code === false) { //fallback to system move $code = system("mv -f {$tempFile}, {$script}"); if (!$code == 0) { throw new RuntimeException('Update Failed', 3); } } $this->logger->info('Version updated.'); system($script . ' init'); system($script . ' --version'); }
private function _test($downloader) { $instance = DownloadFactory::getInstance($this->logger, new OptionResult(), $downloader); if ($instance->hasSupport(false)) { $actualFilePath = tempnam(Config::getTempFileDir(), ''); $instance->download('http://httpbin.org/', $actualFilePath); $this->assertFileExists($actualFilePath); } else { $this->markTestSkipped(); } }
public function execute($appName) { $apps = AppStore::all(); if (!isset($apps[$appName])) { throw new Exception("App {$appName} not found."); } $app = $apps[$appName]; $targetDir = Config::getRoot() . DIRECTORY_SEPARATOR . 'bin'; $target = $targetDir . DIRECTORY_SEPARATOR . $app['as']; DownloadFactory::getInstance($this->logger, $this->options)->download($app['url'], $target); $this->logger->info('Changing permissions to 0755'); if ($mod = $this->options->chmod) { chmod($target, octdec($mod)); } else { chmod($target, 0755); } $this->logger->info("Downloaded at {$target}"); }
private static function downloadReleaseListFromOfficialSite($version, OptionResult $options = null) { $max = $options && $options->old ? 1000 : 100; $url = "https://secure.php.net/releases/index.php?json&version={$version}&max={$max}"; $file = DownloadFactory::getInstance(Logger::getInstance(), $options)->download($url); $json = file_get_contents($file); return json_decode($json, true); }