From 211d4632bba1084914cb22995973abe164e14ec2 Mon Sep 17 00:00:00 2001 From: Jerome TAMARELLE Date: Fri, 13 Nov 2015 16:49:14 +0100 Subject: [PATCH] Fix compatibility with PHP 5.3 --- src/Composer/Repository/Vcs/GitLabDriver.php | 2 +- src/Composer/Util/GitLab.php | 10 +++++----- src/Composer/Util/RemoteFilesystem.php | 13 +++++-------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/Composer/Repository/Vcs/GitLabDriver.php b/src/Composer/Repository/Vcs/GitLabDriver.php index 29ff16138..5934edf02 100644 --- a/src/Composer/Repository/Vcs/GitLabDriver.php +++ b/src/Composer/Repository/Vcs/GitLabDriver.php @@ -333,7 +333,7 @@ class GitLabDriver extends VcsDriver throw $e; } } - } + } /** * Uses the config `gitlab-domains` to see if the driver supports the url for the diff --git a/src/Composer/Util/GitLab.php b/src/Composer/Util/GitLab.php index 8496476b4..bf38ca1f9 100644 --- a/src/Composer/Util/GitLab.php +++ b/src/Composer/Util/GitLab.php @@ -82,7 +82,7 @@ class GitLab $this->io->writeError(sprintf('A token will be created and stored in "%s", your password will never be stored', $this->config->getAuthConfigSource()->getName())); - $this->io->writeError('To revoke access to this token you can visit ' . $this->config->get('gitlab-domains')[0] . '/profile/applications'); + $this->io->writeError('To revoke access to this token you can visit ' . $originUrl . '/profile/applications'); $attemptCounter = 0; @@ -90,7 +90,7 @@ class GitLab try { $response = $this->createToken($originUrl); } catch (TransportException $e) { - // 401 is bad credentials, + // 401 is bad credentials, // 403 is max login attempts exceeded if (in_array($e->getCode(), array(403, 401))) { @@ -100,8 +100,8 @@ class GitLab $this->io->writeError('Maximum number of login attempts exceeded. Please try again later.'); } - $this->io->writeError('You can also manually create a personal token at ' . $this->config->get('gitlab-domains')[0] . '/profile/applications'); - $this->io->writeError('Add it using "composer config gitlab-oauth.' . $this->config->get('gitlab-domains')[0] . ' "'); + $this->io->writeError('You can also manually create a personal token at ' . $originUrl . '/profile/applications'); + $this->io->writeError('Add it using "composer config gitlab-oauth.' . $originUrl . ' "'); continue; } @@ -143,7 +143,7 @@ class GitLab array( 'username' => $username, 'password' => $password, - 'grant_type' => 'password', + 'grant_type' => 'password', ) ); $options = array( diff --git a/src/Composer/Util/RemoteFilesystem.php b/src/Composer/Util/RemoteFilesystem.php index cc4b9e583..0a2be3441 100644 --- a/src/Composer/Util/RemoteFilesystem.php +++ b/src/Composer/Util/RemoteFilesystem.php @@ -168,7 +168,7 @@ class RemoteFilesystem if (isset($options['http'])) { $options['http']['ignore_errors'] = true; } - + $ctx = StreamContextFactory::getContext($fileUrl, $options, array('notification' => array($this, 'callbackGet'))); if ($this->progress) { @@ -362,8 +362,8 @@ class RemoteFilesystem ) { throw new TransportException('Could not authenticate against '.$this->originUrl, 401); } - } else if ($this->config && in_array($this->originUrl, $this->config->get('gitlab-domains'), true)) { - $message = "\n".'Could not fetch '.$this->fileUrl.', enter your ' . $this->config->get('gitlab-domains')[0] . ' credentials ' .($httpStatus === 401 ? 'to access private repos' : 'to go over the API rate limit'); + } elseif ($this->config && in_array($this->originUrl, $this->config->get('gitlab-domains'), true)) { + $message = "\n".'Could not fetch '.$this->fileUrl.', enter your ' . $this->originUrl . ' credentials ' .($httpStatus === 401 ? 'to access private repos' : 'to go over the API rate limit'); $gitLabUtil = new GitLab($this->io, $this->config, null); if (!$gitLabUtil->authorizeOAuth($this->originUrl) && (!$this->io->isInteractive() || !$gitLabUtil->authorizeOAuthInteractively($this->originUrl, $message)) @@ -432,9 +432,9 @@ class RemoteFilesystem $auth = $this->io->getAuthentication($originUrl); if ('github.com' === $originUrl && 'x-oauth-basic' === $auth['password']) { $options['github-token'] = $auth['username']; - } elseif ($originUrl === $this->config->get('gitlab-domains')[0]) { + } elseif ($this->config && in_array($originUrl, $this->config->get('gitlab-domains'), true)) { if($auth['password'] === 'oauth2') { - $headers[] = 'Authorization: Bearer '.$auth['username']; + $headers[] = 'Authorization: Bearer '.$auth['username']; } } else { $authStr = base64_encode($auth['username'] . ':' . $auth['password']); @@ -449,9 +449,6 @@ class RemoteFilesystem $options['http']['header'][] = $header; } - if($this->config && $this->config->get('gitlab-domains') && $originUrl == $this->config->get('gitlab-domains')[0]) { - $options['retry-auth-failure'] = false; - } return $options; } }