Example #1
0
 /**
  * @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());
 }
Example #2
0
 /**
  * @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));
 }
Example #3
0
File: App.php Project: pagon/core
 /**
  * Flush output
  */
 public function flush()
 {
     // Send headers
     if (!$this->injectors['cli']) {
         $this->output->sendHeader();
     }
     // Send
     echo $this->output->body();
     // Clear
     $this->output->clear();
 }
Example #4
0
 /**
  * @param PharAlias $alias
  *
  * @return Release
  * @throws InstallationFailedException
  * @throws ResolveException
  *
  */
 private function resolveAlias(PharAlias $alias)
 {
     foreach ($this->aliasResolver->resolve($alias) as $repoUrl) {
         try {
             $repo = $this->pharIoRepositoryFactory->getRepository($repoUrl);
             $releases = $repo->getReleases($alias);
             return $releases->getLatest($alias->getVersionConstraint());
         } catch (ResolveException $e) {
             $this->output->writeWarning(sprintf('Resolving alias %s with repository %s failed: %s', $alias, $repoUrl, $e->getMessage()));
             continue;
         }
     }
     throw new ResolveException(sprintf('Could not resolve alias %s', $alias));
 }
Example #5
0
 /**
  * @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);
 }
Example #7
0
 /**
  * @param string $keyId
  *
  * @return string
  */
 public function downloadKey($keyId)
 {
     $this->output->writeInfo(sprintf('Downloading key %s', $keyId));
     return $this->keyDownloader->download($keyId);
 }
Example #8
0
 /**
  * @param string $message
  *
  * @return bool
  */
 public function confirm($message)
 {
     $this->output->writeText(rtrim($message) . ' [Y|n] ');
     $response = fgetc(STDIN);
     return trim($response) === '' || strpos('Yy', $response[0]) !== false;
 }