Adds Composer\Factory::createRemoteFilesystem():
- Implemented in self-update command - Added to Composer\IO\BaseIO the getInputOption() and getInputArgument() getters to allow access to input - Fixed some minor bugspull/2745/head
parent
6f0f17355f
commit
9881d76216
|
@ -287,7 +287,7 @@ EOT
|
||||||
'prepend-autoloader' => array($booleanValidator, $booleanNormalizer),
|
'prepend-autoloader' => array($booleanValidator, $booleanNormalizer),
|
||||||
'disable-tls' => array($booleanValidator, $booleanNormalizer),
|
'disable-tls' => array($booleanValidator, $booleanNormalizer),
|
||||||
'cafile' => array(
|
'cafile' => array(
|
||||||
function ($val) { return file_exists($val) && is_readable($val); }
|
function ($val) { return file_exists($val) && is_readable($val); },
|
||||||
function ($val) { return $val === 'null' ? null : $val; }
|
function ($val) { return $val === 'null' ? null : $val; }
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -61,40 +61,12 @@ EOT
|
||||||
{
|
{
|
||||||
$config = Factory::createConfig();
|
$config = Factory::createConfig();
|
||||||
|
|
||||||
$disableTls = false;
|
|
||||||
if($config->get('disable-tls') === true || $input->getOption('disable-tls')) {
|
if($config->get('disable-tls') === true || $input->getOption('disable-tls')) {
|
||||||
$output->writeln('<warning>You are running Composer with SSL/TLS protection disabled.</warning>');
|
|
||||||
$baseUrl = 'http://' . self::HOMEPAGE;
|
$baseUrl = 'http://' . self::HOMEPAGE;
|
||||||
$disableTls = true;
|
|
||||||
} elseif (!extension_loaded('openssl')) {
|
|
||||||
$output->writeln('<error>The openssl extension is required for SSL/TLS protection but is not available.</error>');
|
|
||||||
$output->writeln('<error>You can disable this error, at your own risk, by enabling the \'disable-tls\' option.</error>');
|
|
||||||
return 1;
|
|
||||||
} else {
|
} else {
|
||||||
$baseUrl = 'https://' . self::HOMEPAGE;
|
$baseUrl = 'https://' . self::HOMEPAGE;
|
||||||
}
|
}
|
||||||
|
$remoteFilesystem = Factory::createRemoteFilesystem($this->getIO(), $config);
|
||||||
$remoteFilesystemOptions = array();
|
|
||||||
if ($disableTls === false) {
|
|
||||||
if (!is_null($config->get('cafile'))) {
|
|
||||||
$remoteFilesystemOptions = array('ssl'=>array('cafile'=>$config->get('cafile')));
|
|
||||||
}
|
|
||||||
if (!is_null($input->getOption('cafile'))) {
|
|
||||||
$remoteFilesystemOptions = array('ssl'=>array('cafile'=>$input->getOption('cafile')));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
$remoteFilesystem = new RemoteFilesystem($this->getIO(), $remoteFilesystemOptions, $disableTls);
|
|
||||||
} catch (TransportException $e) {
|
|
||||||
if (preg_match('|cafile|', $e->getMessage())) {
|
|
||||||
$output->writeln('<error>' . $e->getMessage() . '</error>');
|
|
||||||
$output->writeln('<error>Unable to locate a valid CA certificate file. You must set a valid \'cafile\' option.</error>');
|
|
||||||
$output->writeln('<error>You can alternatively disable this error, at your own risk, by enabling the \'disable-tls\' option.</error>');
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$cacheDir = $config->get('cache-dir');
|
$cacheDir = $config->get('cache-dir');
|
||||||
$rollbackDir = $config->get('home');
|
$rollbackDir = $config->get('home');
|
||||||
|
|
|
@ -142,6 +142,7 @@ class Config
|
||||||
case 'cache-files-dir':
|
case 'cache-files-dir':
|
||||||
case 'cache-repo-dir':
|
case 'cache-repo-dir':
|
||||||
case 'cache-vcs-dir':
|
case 'cache-vcs-dir':
|
||||||
|
case 'cafile':
|
||||||
// convert foo-bar to COMPOSER_FOO_BAR and check if it exists since it overrides the local config
|
// convert foo-bar to COMPOSER_FOO_BAR and check if it exists since it overrides the local config
|
||||||
$env = 'COMPOSER_' . strtoupper(strtr($key, '-', '_'));
|
$env = 'COMPOSER_' . strtoupper(strtr($key, '-', '_'));
|
||||||
|
|
||||||
|
@ -214,7 +215,7 @@ class Config
|
||||||
return $this->config[$key];
|
return $this->config[$key];
|
||||||
|
|
||||||
case 'disable-tls':
|
case 'disable-tls':
|
||||||
return $this->config[$key]!== 'false' && (bool) $this->config[$key];
|
return $this->config[$key] !== 'false' && (bool) $this->config[$key];
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (!isset($this->config[$key])) {
|
if (!isset($this->config[$key])) {
|
||||||
|
|
|
@ -467,4 +467,37 @@ class Factory
|
||||||
|
|
||||||
return $factory->createComposer($io, $config, $disablePlugins, $input);
|
return $factory->createComposer($io, $config, $disablePlugins, $input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function createRemoteFilesystem(IOInterface $io, Config $config, $options = array())
|
||||||
|
{
|
||||||
|
$disableTls = false;
|
||||||
|
if($config->get('disable-tls') === true || $io->getInputOption('disable-tls')) {
|
||||||
|
$io->write('<warning>You are running Composer with SSL/TLS protection disabled.</warning>');
|
||||||
|
$disableTls = true;
|
||||||
|
} elseif (!extension_loaded('openssl')) {
|
||||||
|
throw new \RuntimeException('The openssl extension is required for SSL/TLS protection but is not available. '
|
||||||
|
. 'You can disable this error, at your own risk, by passing the \'--disable-tls\' option to this command.');
|
||||||
|
}
|
||||||
|
$remoteFilesystemOptions = array();
|
||||||
|
if ($disableTls === false) {
|
||||||
|
if (!empty($config->get('cafile'))) {
|
||||||
|
$remoteFilesystemOptions = array('ssl'=>array('cafile'=>$config->get('cafile')));
|
||||||
|
}
|
||||||
|
if (!empty($io->getInputOption('cafile'))) {
|
||||||
|
$remoteFilesystemOptions = array('ssl'=>array('cafile'=>$io->getInputOption('cafile')));
|
||||||
|
}
|
||||||
|
$remoteFilesystemOptions = array_merge_recursive($remoteFilesystemOptions, $options);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$remoteFilesystem = new RemoteFilesystem($io, $remoteFilesystemOptions, $disableTls);
|
||||||
|
} catch (TransportException $e) {
|
||||||
|
if (preg_match('|cafile|', $e->getMessage())) {
|
||||||
|
$io->write('<error>Unable to locate a valid CA certificate file. You must set a valid \'cafile\' option.</error>');
|
||||||
|
$io->write('<error>A valid CA certificate file is required for SSL/TLS protection.</error>');
|
||||||
|
$io->write('<error>You can disable this error, at your own risk, by passing the \'--disable-tls\' option to this command.</error>');
|
||||||
|
}
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
return $remoteFilesystem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,4 +69,20 @@ abstract class BaseIO implements IOInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function getInputOption($optionName)
|
||||||
|
{
|
||||||
|
return $this->input->getOption($optionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function getInputArgument($ArgumentName)
|
||||||
|
{
|
||||||
|
return $this->input->getArgument($argumentName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ class RemoteFilesystem
|
||||||
private $retry;
|
private $retry;
|
||||||
private $progress;
|
private $progress;
|
||||||
private $lastProgress;
|
private $lastProgress;
|
||||||
private $options;
|
private $options = array();
|
||||||
private $disableTls = false;
|
private $disableTls = false;
|
||||||
private $retryTls = true;
|
private $retryTls = true;
|
||||||
private $retryAuthFailure;
|
private $retryAuthFailure;
|
||||||
|
@ -107,6 +107,11 @@ class RemoteFilesystem
|
||||||
return $this->options;
|
return $this->options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isTlsDisabled()
|
||||||
|
{
|
||||||
|
return $this->disableTls === true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get file content or copy action.
|
* Get file content or copy action.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue