Code style fixes
parent
ef60478926
commit
da44f46b9c
|
@ -13,8 +13,8 @@
|
|||
namespace Composer\Util;
|
||||
|
||||
use Composer\Config;
|
||||
use Composer\IO\IOInterface;
|
||||
use Composer\Downloader\TransportException;
|
||||
use Composer\IO\IOInterface;
|
||||
|
||||
/**
|
||||
* @author François Pluchino <francois.pluchino@opendisplay.com>
|
||||
|
@ -136,6 +136,7 @@ class RemoteFilesystem
|
|||
/**
|
||||
* @param array $headers array of returned headers like from getLastHeaders()
|
||||
* @param string $name header name (case insensitive)
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function findHeaderValue(array $headers, $name)
|
||||
|
@ -156,6 +157,7 @@ class RemoteFilesystem
|
|||
|
||||
/**
|
||||
* @param array $headers array of returned headers like from getLastHeaders()
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function findStatusCode(array $headers)
|
||||
|
@ -183,7 +185,6 @@ class RemoteFilesystem
|
|||
*
|
||||
* @throws TransportException|\Exception
|
||||
* @throws TransportException When the file could not be downloaded
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
protected function get($originUrl, $fileUrl, $additionalOptions = array(), $fileName = null, $progress = true)
|
||||
|
@ -227,7 +228,8 @@ class RemoteFilesystem
|
|||
unset($tempAdditionalOptions);
|
||||
$userlandFollow = isset($options['http']['follow_location']) && !$options['http']['follow_location'];
|
||||
|
||||
$this->io->writeError((substr($fileUrl, 0, 4) === 'http' ? 'Downloading ' : 'Reading ') . $fileUrl, true, IOInterface::DEBUG);
|
||||
$this->io->writeError((substr($fileUrl, 0, 4) === 'http' ? 'Downloading ' : 'Reading ') . $fileUrl, true,
|
||||
IOInterface::DEBUG);
|
||||
|
||||
if (isset($options['github-token'])) {
|
||||
$fileUrl .= (false === strpos($fileUrl, '?') ? '?' : '&') . 'access_token=' . $options['github-token'];
|
||||
|
@ -248,7 +250,8 @@ class RemoteFilesystem
|
|||
$fileUrl = 'http://' . gethostbyname('packagist.org') . substr($fileUrl, 20);
|
||||
}
|
||||
|
||||
$ctx = StreamContextFactory::getContext($fileUrl, $options, array('notification' => array($this, 'callbackGet')));
|
||||
$ctx = StreamContextFactory::getContext($fileUrl, $options,
|
||||
array('notification' => array($this, 'callbackGet')));
|
||||
|
||||
if ($this->progress && !$isRedirect) {
|
||||
$this->io->writeError(" Downloading: <comment>Connecting...</comment>", false);
|
||||
|
@ -256,7 +259,8 @@ class RemoteFilesystem
|
|||
|
||||
// Check for secure HTTP
|
||||
if (($this->scheme === 'http' || substr($fileUrl, 0, 5) !== 'https')
|
||||
&& $this->config && $this->config->get('secure-http')) {
|
||||
&& $this->config && $this->config->get('secure-http')
|
||||
) {
|
||||
// Rewrite unsecure Packagist urls to use https
|
||||
if (substr($fileUrl, 0, 21) === 'http://packagist.org/') {
|
||||
$fileUrl = 'https://packagist.org/' . substr($fileUrl, 21);
|
||||
|
@ -313,7 +317,8 @@ class RemoteFilesystem
|
|||
'<error>Retrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info</error>',
|
||||
));
|
||||
|
||||
return $this->get($this->originUrl, $this->fileUrl, $additionalOptions, $this->fileName, $this->progress);
|
||||
return $this->get($this->originUrl, $this->fileUrl, $additionalOptions, $this->fileName,
|
||||
$this->progress);
|
||||
}
|
||||
|
||||
throw $e;
|
||||
|
@ -334,7 +339,8 @@ class RemoteFilesystem
|
|||
// fail 4xx and 5xx responses and capture the response
|
||||
if ($statusCode && $statusCode >= 400 && $statusCode <= 599) {
|
||||
if (!$this->retry) {
|
||||
$e = new TransportException('The "'.$this->fileUrl.'" file could not be downloaded ('.$http_response_header[0].')', $statusCode);
|
||||
$e = new TransportException('The "' . $this->fileUrl . '" file could not be downloaded (' . $http_response_header[0] . ')',
|
||||
$statusCode);
|
||||
$e->setHeaders($http_response_header);
|
||||
$e->setResponse($result);
|
||||
$e->setStatusCode($statusCode);
|
||||
|
@ -374,7 +380,8 @@ class RemoteFilesystem
|
|||
'<error>Retrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info</error>',
|
||||
));
|
||||
|
||||
return $this->get($this->originUrl, $this->fileUrl, $additionalOptions, $this->fileName, $this->progress);
|
||||
return $this->get($this->originUrl, $this->fileUrl, $additionalOptions, $this->fileName,
|
||||
$this->progress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -436,7 +443,8 @@ class RemoteFilesystem
|
|||
if ($this->retry) {
|
||||
$this->retry = false;
|
||||
|
||||
$result = $this->get($this->originUrl, $this->fileUrl, $additionalOptions, $this->fileName, $this->progress);
|
||||
$result = $this->get($this->originUrl, $this->fileUrl, $additionalOptions, $this->fileName,
|
||||
$this->progress);
|
||||
|
||||
if ($this->storeAuth && $this->config) {
|
||||
$authHelper = new AuthHelper($this->io, $this->config);
|
||||
|
@ -448,7 +456,8 @@ class RemoteFilesystem
|
|||
}
|
||||
|
||||
if (false === $result) {
|
||||
$e = new TransportException('The "'.$this->fileUrl.'" file could not be downloaded: '.$errorMessage, $errorCode);
|
||||
$e = new TransportException('The "' . $this->fileUrl . '" file could not be downloaded: ' . $errorMessage,
|
||||
$errorCode);
|
||||
if (!empty($http_response_header[0])) {
|
||||
$e->setHeaders($http_response_header);
|
||||
}
|
||||
|
@ -460,7 +469,8 @@ class RemoteFilesystem
|
|||
'<error>Retrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info</error>',
|
||||
));
|
||||
|
||||
return $this->get($this->originUrl, $this->fileUrl, $additionalOptions, $this->fileName, $this->progress);
|
||||
return $this->get($this->originUrl, $this->fileUrl, $additionalOptions, $this->fileName,
|
||||
$this->progress);
|
||||
}
|
||||
|
||||
throw $e;
|
||||
|
@ -482,6 +492,7 @@ class RemoteFilesystem
|
|||
* @param int $messageCode The message code
|
||||
* @param int $bytesTransferred The loaded size
|
||||
* @param int $bytesMax The total size
|
||||
*
|
||||
* @throws TransportException
|
||||
*/
|
||||
protected function callbackGet($notificationCode, $severity, $message, $messageCode, $bytesTransferred, $bytesMax)
|
||||
|
@ -491,7 +502,8 @@ class RemoteFilesystem
|
|||
if (400 === $messageCode) {
|
||||
// This might happen if your host is secured by ssl client certificate authentication
|
||||
// but you do not send an appropriate certificate
|
||||
throw new TransportException("The '" . $this->fileUrl . "' URL could not be accessed: " . $message, $messageCode);
|
||||
throw new TransportException("The '" . $this->fileUrl . "' URL could not be accessed: " . $message,
|
||||
$messageCode);
|
||||
}
|
||||
// intentional fallthrough to the next case as the notificationCode
|
||||
// isn't always consistent and we should inspect the messageCode for 401s
|
||||
|
@ -546,7 +558,8 @@ class RemoteFilesystem
|
|||
$message = "\n" . 'Could not fetch ' . $this->fileUrl . ', please create a GitHub OAuth token ' . ($httpStatus === 404 ? 'to access private repos' : 'to go over the API rate limit');
|
||||
$gitHubUtil = new GitHub($this->io, $this->config, null);
|
||||
if (!$gitHubUtil->authorizeOAuth($this->originUrl)
|
||||
&& (!$this->io->isInteractive() || !$gitHubUtil->authorizeOAuthInteractively($this->originUrl, $message))
|
||||
&& (!$this->io->isInteractive() || !$gitHubUtil->authorizeOAuthInteractively($this->originUrl,
|
||||
$message))
|
||||
) {
|
||||
throw new TransportException('Could not authenticate against ' . $this->originUrl, 401);
|
||||
}
|
||||
|
@ -554,7 +567,8 @@ class RemoteFilesystem
|
|||
$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->scheme, $this->originUrl, $message))
|
||||
&& (!$this->io->isInteractive() || !$gitLabUtil->authorizeOAuthInteractively($this->scheme,
|
||||
$this->originUrl, $message))
|
||||
) {
|
||||
throw new TransportException('Could not authenticate against ' . $this->originUrl, 401);
|
||||
}
|
||||
|
@ -577,10 +591,12 @@ class RemoteFilesystem
|
|||
}
|
||||
// fail if we already have auth
|
||||
if ($this->io->hasAuthentication($this->originUrl)) {
|
||||
throw new TransportException("Invalid credentials for '" . $this->fileUrl . "', aborting.", $httpStatus);
|
||||
throw new TransportException("Invalid credentials for '" . $this->fileUrl . "', aborting.",
|
||||
$httpStatus);
|
||||
}
|
||||
|
||||
$this->io->overwriteError(' Authentication required (<info>'.parse_url($this->fileUrl, PHP_URL_HOST).'</info>):');
|
||||
$this->io->overwriteError(' Authentication required (<info>' . parse_url($this->fileUrl,
|
||||
PHP_URL_HOST) . '</info>):');
|
||||
$username = $this->io->ask(' Username: ');
|
||||
$password = $this->io->askAndHideAnswer(' Password: ');
|
||||
$this->io->setAuthentication($this->originUrl, $username, $password);
|
||||
|
@ -690,7 +706,8 @@ class RemoteFilesystem
|
|||
$urlHost = parse_url($this->fileUrl, PHP_URL_HOST);
|
||||
|
||||
// Replace path using hostname as an anchor.
|
||||
$targetUrl = preg_replace('{^(.+(?://|@)'.preg_quote($urlHost).'(?::\d+)?)(?:[/\?].*)?$}', '\1'.$locationHeader, $this->fileUrl);
|
||||
$targetUrl = preg_replace('{^(.+(?://|@)' . preg_quote($urlHost) . '(?::\d+)?)(?:[/\?].*)?$}',
|
||||
'\1' . $locationHeader, $this->fileUrl);
|
||||
} else {
|
||||
// Relative path; e.g. foo
|
||||
// This actually differs from PHP which seems to add duplicate slashes.
|
||||
|
@ -701,7 +718,8 @@ class RemoteFilesystem
|
|||
if (!empty($targetUrl)) {
|
||||
$this->redirects++;
|
||||
|
||||
$this->io->writeError(sprintf('Following redirect (%u) %s', $this->redirects, $targetUrl), true, IOInterface::DEBUG);
|
||||
$this->io->writeError(sprintf('Following redirect (%u) %s', $this->redirects, $targetUrl), true,
|
||||
IOInterface::DEBUG);
|
||||
|
||||
$additionalOptions['redirects'] = $this->redirects;
|
||||
|
||||
|
@ -768,7 +786,6 @@ class RemoteFilesystem
|
|||
/**
|
||||
* CN_match and SNI_server_name are only known once a URL is passed.
|
||||
* They will be set in the getOptionsForUrl() method which receives a URL.
|
||||
*
|
||||
* cafile or capath can be overridden by passing in those options to constructor.
|
||||
*/
|
||||
$defaults = array(
|
||||
|
@ -830,24 +847,17 @@ class RemoteFilesystem
|
|||
/**
|
||||
* This method was adapted from Sslurp.
|
||||
* https://github.com/EvanDotPro/Sslurp
|
||||
*
|
||||
* (c) Evan Coury <me@evancoury.com>
|
||||
*
|
||||
* For the full copyright and license information, please see below:
|
||||
*
|
||||
* Copyright (c) 2013, Evan Coury
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
|
@ -973,11 +983,13 @@ class RemoteFilesystem
|
|||
));
|
||||
}
|
||||
|
||||
$context = StreamContextFactory::getContext($url, $options, array('options' => array(
|
||||
$context = StreamContextFactory::getContext($url, $options, array(
|
||||
'options' => array(
|
||||
'ssl' => array(
|
||||
'capture_peer_cert' => true,
|
||||
'verify_peer' => false, // Yes this is fucking insane! But PHP is lame.
|
||||
), ),
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
// Ideally this would just use stream_socket_client() to avoid sending a
|
||||
|
|
Loading…
Reference in New Issue