/** * @param Url $url * * @return File * @throws DownloadFailedException */ public function download(Url $url) { $this->output->writeInfo(sprintf('Downloading %s', $url)); $response = $this->curl->get($url); if ($response->getHttpCode() !== 200) { throw new DownloadFailedException(sprintf('Download failed (HTTP status code %s) %s', $response->getHttpCode(), $response->getErrorMessage())); } if (empty($response->getBody())) { throw new DownloadFailedException('Download failed - response is empty'); } return new File($this->getFilename($url), $response->getBody()); }
/** * @param string $keyId * * @return string * @throws DownloadFailedException */ public function download($keyId) { $params = ['search' => '0x' . $keyId, 'op' => 'get', 'options' => 'mr']; foreach ($this->keyServers as $keyServer) { $this->output->writeInfo(sprintf('Trying %s', $keyServer)); $result = $this->httpClient->get(new Url($keyServer . self::PATH), $params); if ($result->getHttpCode() == 200) { $this->output->writeInfo('Sucessfully downloaded key'); return $result->getBody(); } $this->output->writeWarning(sprintf('Failed with status code %s: %s', $result->getHttpCode(), $result->getErrorMessage())); } throw new DownloadFailedException(sprintf('Key %s not found on key servers', $keyId)); }
/** * @param File $phar * @param string $destination */ private function link(File $phar, $destination) { $this->output->writeInfo(sprintf('Symlinking %s to %s', $phar->getFilename(), $destination)); symlink($this->pharDirectory . DIRECTORY_SEPARATOR . $phar->getFilename(), $destination); }
/** * @throws DownloadFailedException */ public function downloadFromSource() { $this->output->writeInfo(sprintf('Downloading repository list from %s', $this->sourceUrl)); $file = $this->fileDownloader->download($this->sourceUrl); $file->saveAs($this->filename); }
/** * @param string $keyId * * @return string */ public function downloadKey($keyId) { $this->output->writeInfo(sprintf('Downloading key %s', $keyId)); return $this->keyDownloader->download($keyId); }