1
0
Fork 0

Fix compatibility with PHP 5.3

pull/3765/head
Jerome TAMARELLE 2015-11-13 16:49:14 +01:00
parent 6ec9f5ff02
commit 211d4632bb
3 changed files with 11 additions and 14 deletions

View File

@ -333,7 +333,7 @@ class GitLabDriver extends VcsDriver
throw $e; throw $e;
} }
} }
} }
/** /**
* Uses the config `gitlab-domains` to see if the driver supports the url for the * Uses the config `gitlab-domains` to see if the driver supports the url for the

View File

@ -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(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; $attemptCounter = 0;
@ -90,7 +90,7 @@ class GitLab
try { try {
$response = $this->createToken($originUrl); $response = $this->createToken($originUrl);
} catch (TransportException $e) { } catch (TransportException $e) {
// 401 is bad credentials, // 401 is bad credentials,
// 403 is max login attempts exceeded // 403 is max login attempts exceeded
if (in_array($e->getCode(), array(403, 401))) { 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('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('You can also manually create a personal token at ' . $originUrl . '/profile/applications');
$this->io->writeError('Add it using "composer config gitlab-oauth.' . $this->config->get('gitlab-domains')[0] . ' <token>"'); $this->io->writeError('Add it using "composer config gitlab-oauth.' . $originUrl . ' <token>"');
continue; continue;
} }
@ -143,7 +143,7 @@ class GitLab
array( array(
'username' => $username, 'username' => $username,
'password' => $password, 'password' => $password,
'grant_type' => 'password', 'grant_type' => 'password',
) )
); );
$options = array( $options = array(

View File

@ -168,7 +168,7 @@ class RemoteFilesystem
if (isset($options['http'])) { if (isset($options['http'])) {
$options['http']['ignore_errors'] = true; $options['http']['ignore_errors'] = true;
} }
$ctx = StreamContextFactory::getContext($fileUrl, $options, array('notification' => array($this, 'callbackGet'))); $ctx = StreamContextFactory::getContext($fileUrl, $options, array('notification' => array($this, 'callbackGet')));
if ($this->progress) { if ($this->progress) {
@ -362,8 +362,8 @@ class RemoteFilesystem
) { ) {
throw new TransportException('Could not authenticate against '.$this->originUrl, 401); throw new TransportException('Could not authenticate against '.$this->originUrl, 401);
} }
} else if ($this->config && in_array($this->originUrl, $this->config->get('gitlab-domains'), true)) { } elseif ($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'); $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); $gitLabUtil = new GitLab($this->io, $this->config, null);
if (!$gitLabUtil->authorizeOAuth($this->originUrl) if (!$gitLabUtil->authorizeOAuth($this->originUrl)
&& (!$this->io->isInteractive() || !$gitLabUtil->authorizeOAuthInteractively($this->originUrl, $message)) && (!$this->io->isInteractive() || !$gitLabUtil->authorizeOAuthInteractively($this->originUrl, $message))
@ -432,9 +432,9 @@ class RemoteFilesystem
$auth = $this->io->getAuthentication($originUrl); $auth = $this->io->getAuthentication($originUrl);
if ('github.com' === $originUrl && 'x-oauth-basic' === $auth['password']) { if ('github.com' === $originUrl && 'x-oauth-basic' === $auth['password']) {
$options['github-token'] = $auth['username']; $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') { if($auth['password'] === 'oauth2') {
$headers[] = 'Authorization: Bearer '.$auth['username']; $headers[] = 'Authorization: Bearer '.$auth['username'];
} }
} else { } else {
$authStr = base64_encode($auth['username'] . ':' . $auth['password']); $authStr = base64_encode($auth['username'] . ':' . $auth['password']);
@ -449,9 +449,6 @@ class RemoteFilesystem
$options['http']['header'][] = $header; $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; return $options;
} }
} }