From 6cf860669f1556cca2d84861e1fbfae44682ca04 Mon Sep 17 00:00:00 2001 From: Sander Marechal Date: Wed, 3 Oct 2012 11:56:31 +0200 Subject: [PATCH] Add repository stream context options Add support for passing stream context options to the StreamContextFactory. This allows support for SSH keyfiles, SSL certificates and much more. Example: { "repositories": [ { "type": "composer", "url": "ssh2.sftp://host:22/path/to/packages.json", "options": { "ssh2": { "username": "composer", "pubkey_file": "/path/to/composer.key.pub", "privkey_file": "/path/to/composer.key" } } } ] } --- src/Composer/Repository/ComposerRepository.php | 8 +++++++- src/Composer/Util/RemoteFilesystem.php | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index 83084d0ae..5904e6a94 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -27,6 +27,7 @@ use Composer\Util\RemoteFilesystem; class ComposerRepository extends ArrayRepository implements NotifiableRepositoryInterface, StreamableRepositoryInterface { protected $config; + protected $options; protected $url; protected $io; protected $cache; @@ -46,7 +47,12 @@ class ComposerRepository extends ArrayRepository implements NotifiableRepository throw new \UnexpectedValueException('Invalid url given for Composer repository: '.$repoConfig['url']); } + if (!isset($repoConfig['options'])) { + $repoConfig['options'] = array(); + } + $this->config = $config; + $this->options = $repoConfig['options']; $this->url = $repoConfig['url']; $this->io = $io; $this->cache = new Cache($io, $config->get('home').'/cache/'.preg_replace('{[^a-z0-9.]}i', '-', $this->url)); @@ -199,7 +205,7 @@ class ComposerRepository extends ArrayRepository implements NotifiableRepository $jsonUrl = $this->url . '/packages.json'; } - $json = new JsonFile($jsonUrl, new RemoteFilesystem($this->io)); + $json = new JsonFile($jsonUrl, new RemoteFilesystem($this->io, $this->options)); $data = $json->read(); if (!empty($data['notify'])) { diff --git a/src/Composer/Util/RemoteFilesystem.php b/src/Composer/Util/RemoteFilesystem.php index e82313033..f2dfaf842 100644 --- a/src/Composer/Util/RemoteFilesystem.php +++ b/src/Composer/Util/RemoteFilesystem.php @@ -30,15 +30,17 @@ class RemoteFilesystem private $result; private $progress; private $lastProgress; + private $options; /** * Constructor. * * @param IOInterface $io The IO instance */ - public function __construct(IOInterface $io) + public function __construct(IOInterface $io, $options = array()) { $this->io = $io; + $this->options = $options; } /** @@ -241,6 +243,8 @@ class RemoteFilesystem $options['http']['header'] .= "Authorization: Basic $authStr\r\n"; } + $options = array_merge_recursive($options, $this->options); + return $options; } }