diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index 1b3ee0324..761f1b0b1 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -234,7 +234,7 @@ EOT if (null === $repositoryUrl) { $sourceRepo = new CompositeRepository(Factory::createDefaultRepositories($io, $config)); } elseif ("json" === pathinfo($repositoryUrl, PATHINFO_EXTENSION)) { - $sourceRepo = new FilesystemRepository(new JsonFile($repositoryUrl, new RemoteFilesystem($io))); + $sourceRepo = new FilesystemRepository(new JsonFile($repositoryUrl, Factory::createRemoteFilesystem($io, $config))); } elseif (0 === strpos($repositoryUrl, 'http')) { $sourceRepo = new ComposerRepository(array('url' => $repositoryUrl), $io, $config); } else { diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 2f8c048dc..db982f1d7 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -14,6 +14,7 @@ namespace Composer\Downloader; use Composer\Config; use Composer\Cache; +use Composer\Factory; use Composer\IO\IOInterface; use Composer\Package\PackageInterface; use Composer\Package\Version\VersionParser; @@ -56,7 +57,7 @@ class FileDownloader implements DownloaderInterface $this->io = $io; $this->config = $config; $this->eventDispatcher = $eventDispatcher; - $this->rfs = $rfs ?: new RemoteFilesystem($io); + $this->rfs = $rfs ?: Factory::createRemoteFilesystem($this->io, $config); $this->filesystem = $filesystem ?: new Filesystem(); $this->cache = $cache; diff --git a/src/Composer/Downloader/VcsDownloader.php b/src/Composer/Downloader/VcsDownloader.php index 4e06d63f8..399029f13 100644 --- a/src/Composer/Downloader/VcsDownloader.php +++ b/src/Composer/Downloader/VcsDownloader.php @@ -13,6 +13,7 @@ namespace Composer\Downloader; use Composer\Config; +use Composer\Factory; use Composer\Package\PackageInterface; use Composer\Package\Version\VersionParser; use Composer\Util\ProcessExecutor; diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index 272e8365d..69a40a60a 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -195,24 +195,7 @@ class Factory if (is_string($localConfig)) { $composerFile = $localConfig; - $rfs = null; - if (preg_match("|^https?://|i", $localConfig)) { - $disableTls = false; - if($input->getOption('disable-tls')) { - //$output->writeln('You are running Composer with SSL/TLS protection disabled.'); //TODO - $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.'); - } - - $rfsOptions = array(); - if ($disableTls === false && !is_null($input->getOption('cafile'))) { - $rfsOptions = array('ssl'=>array('cafile'=>$input->getOption('cafile'))); - } - $rfs = new RemoteFilesystem($io, $rfsOptions, $disableTls); - } - + $rfs = Factory::createRemoteFilesystem($io); $file = new JsonFile($localConfig, $rfs); if (!$file->exists()) { @@ -468,10 +451,16 @@ class Factory return $factory->createComposer($io, $config, $disablePlugins, $input); } - public static function createRemoteFilesystem(IOInterface $io, Config $config, $options = array()) + /** + * @param IOInterface $io IO instance + * @param Config $config Config instance + * @param array $options Array of options passed directly to RemoteFilesystem constructor + * @return RemoteFilesystem + */ + public static function createRemoteFilesystem(IOInterface $io, Config $config = null, $options = array()) { $disableTls = false; - if($config->get('disable-tls') === true || $io->getInputOption('disable-tls')) { + if((isset($config) && $config->get('disable-tls') === true) || $io->getInputOption('disable-tls')) { $io->write('You are running Composer with SSL/TLS protection disabled.'); $disableTls = true; } elseif (!extension_loaded('openssl')) { @@ -480,7 +469,7 @@ class Factory } $remoteFilesystemOptions = array(); if ($disableTls === false) { - if (!empty($config->get('cafile'))) { + if (isset($config) && !empty($config->get('cafile'))) { $remoteFilesystemOptions = array('ssl'=>array('cafile'=>$config->get('cafile'))); } if (!empty($io->getInputOption('cafile'))) { diff --git a/src/Composer/IO/IOInterface.php b/src/Composer/IO/IOInterface.php index f117ce974..cd2a6b7f6 100644 --- a/src/Composer/IO/IOInterface.php +++ b/src/Composer/IO/IOInterface.php @@ -164,4 +164,22 @@ interface IOInterface * @param Config $config */ public function loadConfiguration(Config $config); + + /** + * Get the value of an input option + * + * @param string $optionName The name of the option whose value is to be retrieved + * + * @return mixed + */ + public function getInputOption($optionName); + + /** + * Get the value of an input argument + * + * @param string $argumentName The name of the argument whose value is to be retrieved + * + * @return mixed + */ + public function getInputArgument($argumentName); } diff --git a/src/Composer/IO/NullIO.php b/src/Composer/IO/NullIO.php index f3ecde0cb..de5bb52ae 100644 --- a/src/Composer/IO/NullIO.php +++ b/src/Composer/IO/NullIO.php @@ -104,4 +104,20 @@ class NullIO extends BaseIO { return null; } + + /** + * {@inheritDoc} + */ + public function getInputOption($optionName) + { + return null; + } + + /** + * {@inheritDoc} + */ + public function getInputArgument($ArgumentName) + { + return null; + } } diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index 1d686cae1..3845f9c39 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -20,6 +20,7 @@ use Composer\DependencyResolver\Pool; use Composer\Json\JsonFile; use Composer\Cache; use Composer\Config; +use Composer\Factory; use Composer\IO\IOInterface; use Composer\Util\RemoteFilesystem; use Composer\Plugin\PluginEvents; @@ -85,7 +86,7 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository $this->io = $io; $this->cache = new Cache($io, $config->get('cache-repo-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', $this->url), 'a-z0-9.$'); $this->loader = new ArrayLoader(); - $this->rfs = new RemoteFilesystem($this->io, $this->options); + $this->rfs = Factory::createRemoteFilesystem($this->io, $this->config, $this->options); $this->eventDispatcher = $eventDispatcher; } diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index a106385a5..1674b7a0b 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -22,6 +22,7 @@ use Composer\Package\Link; use Composer\Package\LinkConstraint\VersionConstraint; use Composer\Util\RemoteFilesystem; use Composer\Config; +use Composer\Factory; /** * Builds list of package from PEAR channel. @@ -57,7 +58,7 @@ class PearRepository extends ArrayRepository $this->url = rtrim($repoConfig['url'], '/'); $this->io = $io; - $this->rfs = $rfs ?: new RemoteFilesystem($this->io); + $this->rfs = $rfs ?: Factory::createRemoteFilesystem($this->io, $config); $this->vendorAlias = isset($repoConfig['vendor-alias']) ? $repoConfig['vendor-alias'] : null; $this->versionParser = new VersionParser(); } diff --git a/src/Composer/Repository/Vcs/VcsDriver.php b/src/Composer/Repository/Vcs/VcsDriver.php index f1112074e..34297f81b 100644 --- a/src/Composer/Repository/Vcs/VcsDriver.php +++ b/src/Composer/Repository/Vcs/VcsDriver.php @@ -14,6 +14,7 @@ namespace Composer\Repository\Vcs; use Composer\Downloader\TransportException; use Composer\Config; +use Composer\Factory; use Composer\IO\IOInterface; use Composer\Util\ProcessExecutor; use Composer\Util\RemoteFilesystem; @@ -57,7 +58,7 @@ abstract class VcsDriver implements VcsDriverInterface $this->io = $io; $this->config = $config; $this->process = $process ?: new ProcessExecutor($io); - $this->remoteFilesystem = $remoteFilesystem ?: new RemoteFilesystem($io); + $this->remoteFilesystem = $remoteFilesystem ?: Factory::createRemoteFilesystem($this->io, $config); } /** diff --git a/src/Composer/Util/ConfigValidator.php b/src/Composer/Util/ConfigValidator.php index 408342940..9308028b7 100644 --- a/src/Composer/Util/ConfigValidator.php +++ b/src/Composer/Util/ConfigValidator.php @@ -50,7 +50,7 @@ class ConfigValidator // validate json schema $laxValid = false; try { - $json = new JsonFile($file, new RemoteFilesystem($this->io)); //TODO + $json = new JsonFile($file, Factory::createRemoteFilesystem($this->io)); //TODO $manifest = $json->read(); $json->validateSchema(JsonFile::LAX_SCHEMA); diff --git a/src/Composer/Util/GitHub.php b/src/Composer/Util/GitHub.php index b69073d13..0cba17027 100644 --- a/src/Composer/Util/GitHub.php +++ b/src/Composer/Util/GitHub.php @@ -40,7 +40,7 @@ class GitHub $this->io = $io; $this->config = $config; $this->process = $process ?: new ProcessExecutor; - $this->remoteFilesystem = $remoteFilesystem ?: new RemoteFilesystem($io); + $this->remoteFilesystem = $remoteFilesystem ?: Factory::createRemoteFilesystem($this->io, $config); } /** diff --git a/tests/Composer/Test/Downloader/ZipDownloaderTest.php b/tests/Composer/Test/Downloader/ZipDownloaderTest.php index bbe77d7ee..a7d4cde68 100644 --- a/tests/Composer/Test/Downloader/ZipDownloaderTest.php +++ b/tests/Composer/Test/Downloader/ZipDownloaderTest.php @@ -33,7 +33,15 @@ class ZipDownloaderTest extends \PHPUnit_Framework_TestCase $io = $this->getMock('Composer\IO\IOInterface'); $config = $this->getMock('Composer\Config'); - $config->expects($this->any()) + $config->expects($this->at(0)) + ->method('get') + ->with('disable-tls') + ->will($this->returnValue(false)); + $config->expects($this->at(1)) + ->method('get') + ->with('cafile') + ->will($this->returnValue(null)); + $config->expects($this->at(2)) ->method('get') ->with('vendor-dir') ->will($this->returnValue(sys_get_temp_dir().'/composer-zip-test-vendor'));