Undid CS changes

main
cinamo 9 years ago
parent da44f46b9c
commit 4f5b4aff9c

@ -13,8 +13,8 @@
namespace Composer\Util;
use Composer\Config;
use Composer\Downloader\TransportException;
use Composer\IO\IOInterface;
use Composer\Downloader\TransportException;
/**
* @author François Pluchino <francois.pluchino@opendisplay.com>
@ -136,7 +136,6 @@ 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)
@ -157,7 +156,6 @@ class RemoteFilesystem
/**
* @param array $headers array of returned headers like from getLastHeaders()
*
* @return int|null
*/
public function findStatusCode(array $headers)
@ -185,6 +183,7 @@ 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)
@ -228,8 +227,7 @@ 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'];
@ -250,8 +248,7 @@ 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);
@ -317,8 +314,7 @@ 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;
@ -339,8 +335,7 @@ 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);
@ -380,8 +375,7 @@ 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);
}
}
}
@ -443,8 +437,7 @@ 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);
@ -456,8 +449,7 @@ 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);
}
@ -469,8 +461,7 @@ 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;
@ -492,7 +483,6 @@ 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)
@ -502,8 +492,7 @@ 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
@ -558,8 +547,7 @@ 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);
}
@ -567,8 +555,7 @@ 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);
}
@ -591,12 +578,10 @@ 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);
@ -706,8 +691,7 @@ 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.
@ -718,8 +702,7 @@ 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;
@ -786,6 +769,7 @@ 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(
@ -847,17 +831,24 @@ 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
@ -983,13 +974,11 @@ 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…
Cancel
Save