public function referencePackages(PackageSet $packageSet, IOInterface $io, $apiUrl = null)
 {
     if (!$apiUrl) {
         $apiUrl = 'https://php-bach.org';
     }
     $apiUrlFormat = $apiUrl . '/p/%s.json';
     //cURL
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_HEADER, true);
     /** @var Package $package */
     foreach ($packageSet as $package) {
         $packageName = $package->getPackageName();
         $versionName = $package->getVersion();
         $url = sprintf($apiUrlFormat, $packageName);
         curl_setopt($ch, CURLOPT_URL, $url);
         $response = curl_exec($ch);
         $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
         $message = '<info>Checking:</info> ' . $packageName . ' (' . $versionName . ') ...';
         $io->write($message);
         if ('200' === (string) $code) {
             $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
             // ヘッダサイズ取得
             $body = substr($response, $header_size);
             // bodyだけ切り出し
             if ($this->parseResponse($package, $body)) {
                 $io->overwrite('<info>Done.</info>');
             } else {
                 $io->overwrite('<fg=white;bg=magenta>Version not found.</>');
             }
         } elseif ('404' === (string) $code) {
             $io->overwrite('<fg=white;bg=magenta>Package not found.</>');
         } else {
             $io->overwriteError($message . '<error>Connection error.</error>');
         }
     }
     curl_close($ch);
 }
Esempio n. 2
0
 /**
  * @param string $url      URL of the archive on Amazon S3.
  * @param bool   $progress Show progress
  * @param string $to       Target file name
  *
  * @throws \Composer\Downloader\TransportException
  */
 public function download($url, $progress, $to = null)
 {
     list($bucket, $key) = $this->determineBucketAndKey($url);
     if ($progress) {
         $this->io->write("    Downloading: <comment>connection...</comment>", false);
     }
     try {
         $params = array('Bucket' => $bucket, 'Key' => $key);
         if ($to) {
             $params['command.response_body'] = \Guzzle\Http\EntityBody::factory(fopen($to, 'w+'));
         }
         $s3 = self::s3factory($this->config);
         $result = $s3->getObject($params);
         if ($progress) {
             $this->io->overwrite("    Downloading: <comment>100%</comment>");
         }
         if ($to) {
             if (false === file_exists($to) || !filesize($to)) {
                 $errorMessage = sprintf("Unknown error occurred: '%s' was not downloaded from '%s'.", $key, $url);
                 throw new TransportException($errorMessage);
             }
         } else {
             return $result['Body'];
         }
     } catch (\Aws\Common\Exception\InstanceProfileCredentialsException $e) {
         $msg = "Please add key/secret into config.json or set up an IAM profile for your EC2 instance.";
         throw new TransportException($msg, 403, $e);
     } catch (Aws\S3\Exception\S3Exception $e) {
         throw new TransportException("Connection to Amazon S3 failed.", null, $e);
     } catch (TransportException $e) {
         throw $e;
         // just re-throw
     } catch (\Exception $e) {
         throw new TransportException("Problem?", null, $e);
     }
     return $this;
 }
 /**
  * {@inheritDoc}
  */
 public function load(LazyPackageInterface $package)
 {
     if (isset($this->cache[$package->getUniqueName()])) {
         return $this->cache[$package->getUniqueName()];
     }
     $this->validateConfig();
     $filename = $this->assetType->getFilename();
     $msg = 'Reading ' . $filename . ' of <info>' . $package->getName() . '</info> (<comment>' . $package->getPrettyVersion() . '</comment>)';
     if ($this->verbose) {
         $this->io->write($msg);
     } else {
         $this->io->overwrite($msg, false);
     }
     $realPackage = $this->loadRealPackage($package);
     $this->cache[$package->getUniqueName()] = $realPackage;
     if (!$this->verbose) {
         $this->io->overwrite('', false);
     }
     return $realPackage;
 }
Esempio n. 4
0
 public function promptAuth(HttpGetResponse $res, CConfig $config, IO\IOInterface $io)
 {
     $httpCode = $res->info['http_code'];
     // 404s are only handled for github
     if (404 === $httpCode) {
         return false;
     }
     // fail if the console is not interactive
     if (!$io->isInteractive()) {
         switch ($httpCode) {
             case 401:
                 $message = "The '{$this->getURL()}' URL required authentication.\nYou must be using the interactive console to authenticate";
                 break;
             case 403:
                 $message = "The '{$this->getURL()}' URL could not be accessed.";
                 break;
         }
         throw new Downloader\TransportException($message, $httpCode);
     }
     // fail if we already have auth
     if ($io->hasAuthentication($this->origin)) {
         throw new Downloader\TransportException("Invalid credentials for '{$this->getURL()}', aborting.", $httpCode);
     }
     $io->overwrite("    Authentication required (<info>{$this->host}</info>):");
     $username = $io->ask('      Username: '******'      Password: ');
     $io->setAuthentication($this->origin, $username, $password);
     return true;
 }
 /**
  * @param string $message
  * @param callable $task
  */
 private static function runTask($message, callable $task)
 {
     self::$io->write(sprintf('<info> - [ ] %s</info>', $message), false);
     $task();
     self::$io->overwrite(sprintf('<info> - [x] %s</info>', $message), true);
 }