public function __construct($url, IOInterface $io)
 {
     preg_match('#^https://bitbucket\\.org/([^/]+)/([^/]+)/?$#', $url, $match);
     $this->owner = $match[1];
     $this->repository = $match[2];
     parent::__construct($url, $io);
 }
Exemple #2
0
 public function __construct($url, IOInterface $io)
 {
     preg_match('#^(?:https?|git)://github\\.com/([^/]+)/(.+?)(?:\\.git)?$#', $url, $match);
     $this->owner = $match[1];
     $this->repository = $match[2];
     parent::__construct($url, $io);
 }
Exemple #3
0
 public function __construct($url, IOInterface $io, ProcessExecutor $process = null)
 {
     parent::__construct($this->baseUrl = rtrim($url, '/'), $io, $process);
     if (false !== ($pos = strrpos($url, '/trunk'))) {
         $this->baseUrl = substr($url, 0, $pos);
     }
 }
Exemple #4
0
 /**
  * Constructor
  *
  * @param string $url
  * @param IOInterface $io
  * @param ProcessExecutor $process
  * @param RemoteFilesystem $remoteFilesystem
  */
 public function __construct($url, IOInterface $io, ProcessExecutor $process = null, RemoteFilesystem $remoteFilesystem = null)
 {
     preg_match('#^(?:https?|git)://github\\.com/([^/]+)/(.+?)(?:\\.git)?$#', $url, $match);
     $this->owner = $match[1];
     $this->repository = $match[2];
     parent::__construct($url, $io, $process, $remoteFilesystem);
 }
Exemple #5
0
 /**
  * @param string          $url
  * @param IOInterface     $io
  * @param ProcessExecutor $process
  *
  * @return $this
  */
 public function __construct($url, IOInterface $io, ProcessExecutor $process = null)
 {
     $url = self::normalizeUrl($url);
     parent::__construct($this->baseUrl = rtrim($url, '/'), $io, $process);
     if (false !== ($pos = strrpos($url, '/trunk'))) {
         $this->baseUrl = substr($url, 0, $pos);
     }
     $this->util = new SvnUtil($this->baseUrl, $io, $this->process);
 }
 /**
  * {@inheritDoc}
  */
 protected function getContents($url, $fetchingRepoData = false)
 {
     try {
         return parent::getContents($url);
     } catch (TransportException $e) {
         $gitHubUtil = new GitHub($this->io, $this->config, $this->process, $this->remoteFilesystem);
         switch ($e->getCode()) {
             case 401:
             case 404:
                 // try to authorize only if we are fetching the main /repos/foo/bar data, otherwise it must be a real 404
                 if (!$fetchingRepoData) {
                     throw $e;
                 }
                 if ($gitHubUtil->authorizeOAuth($this->originUrl)) {
                     return parent::getContents($url);
                 }
                 if (!$this->io->isInteractive()) {
                     return $this->attemptCloneFallback();
                 }
                 $gitHubUtil->authorizeOAuthInteractively($this->originUrl, 'Your GitHub credentials are required to fetch private repository metadata (<info>' . $this->url . '</info>)');
                 return parent::getContents($url);
             case 403:
                 if (!$this->io->hasAuthentication($this->originUrl) && $gitHubUtil->authorizeOAuth($this->originUrl)) {
                     return parent::getContents($url);
                 }
                 if (!$this->io->isInteractive() && $fetchingRepoData) {
                     return $this->attemptCloneFallback();
                 }
                 $rateLimited = false;
                 foreach ($e->getHeaders() as $header) {
                     if (preg_match('{^X-RateLimit-Remaining: *0$}i', trim($header))) {
                         $rateLimited = true;
                     }
                 }
                 if (!$this->io->hasAuthentication($this->originUrl)) {
                     if (!$this->io->isInteractive()) {
                         $this->io->writeError('<error>GitHub API limit exhausted. Failed to get metadata for the ' . $this->url . ' repository, try running in interactive mode so that you can enter your GitHub credentials to increase the API limit</error>');
                         throw $e;
                     }
                     $gitHubUtil->authorizeOAuthInteractively($this->originUrl, 'API limit exhausted. Enter your GitHub credentials to get a larger API limit (<info>' . $this->url . '</info>)');
                     return parent::getContents($url);
                 }
                 if ($rateLimited) {
                     $rateLimit = $this->getRateLimit($e->getHeaders());
                     $this->io->writeError(sprintf('<error>GitHub API limit (%d calls/hr) is exhausted. You are already authorized so you have to wait until %s before doing more requests</error>', $rateLimit['limit'], $rateLimit['reset']));
                 }
                 throw $e;
             default:
                 throw $e;
         }
     }
 }
Exemple #7
0
 /**
  * {@inheritDoc}
  */
 protected function getContents($url, $fetchingRepoData = false)
 {
     try {
         return parent::getContents($url);
     } catch (TransportException $e) {
         $gitLabUtil = new GitLab($this->io, $this->config, $this->process, $this->remoteFilesystem);
         switch ($e->getCode()) {
             case 401:
             case 404:
                 // try to authorize only if we are fetching the main /repos/foo/bar data, otherwise it must be a real 404
                 if (!$fetchingRepoData) {
                     throw $e;
                 }
                 if ($gitLabUtil->authorizeOAuth($this->originUrl)) {
                     return parent::getContents($url);
                 }
                 if (!$this->io->isInteractive()) {
                     return $this->attemptCloneFallback();
                 }
                 $this->io->writeError('<warning>Failed to download ' . $this->owner . '/' . $this->repository . ':' . $e->getMessage() . '</warning>');
                 $gitLabUtil->authorizeOAuthInteractively($this->scheme, $this->originUrl, 'Your credentials are required to fetch private repository metadata (<info>' . $this->url . '</info>)');
                 return parent::getContents($url);
             case 403:
                 if (!$this->io->hasAuthentication($this->originUrl) && $gitLabUtil->authorizeOAuth($this->originUrl)) {
                     return parent::getContents($url);
                 }
                 if (!$this->io->isInteractive() && $fetchingRepoData) {
                     return $this->attemptCloneFallback();
                 }
                 throw $e;
             default:
                 throw $e;
         }
     }
 }
Exemple #8
0
 public function __construct($url, IOInterface $io, ProcessExecutor $process = null)
 {
     parent::__construct($url, $io, $process);
 }
Exemple #9
0
 public function __construct($url, IOInterface $io, ProcessExecutor $process = null)
 {
     $this->tmpDir = sys_get_temp_dir() . '/composer-' . preg_replace('{[^a-z0-9]}i', '-', $url) . '/';
     parent::__construct($url, $io, $process);
 }
Exemple #10
0
 /**
  * Get the remote content.
  *
  * @param string $url The URL of content
  * @param bool $fetchingRepoData
  *
  * @return mixed The result
  */
 protected function getContentsWithOAuthCredentials($url, $fetchingRepoData = false)
 {
     try {
         return parent::getContents($url);
     } catch (TransportException $e) {
         $bitbucketUtil = new Bitbucket($this->io, $this->config, $this->process, $this->remoteFilesystem);
         if (403 === $e->getCode()) {
             if (!$this->io->hasAuthentication($this->originUrl) && $bitbucketUtil->authorizeOAuth($this->originUrl)) {
                 return parent::getContents($url);
             }
             if (!$this->io->isInteractive() && $fetchingRepoData) {
                 return $this->attemptCloneFallback();
             }
         }
         throw $e;
     }
 }