Move config to all VcsDownloaders, enforce array for github-protocols
parent
7023767501
commit
056dc5d690
|
@ -12,10 +12,6 @@
|
||||||
|
|
||||||
namespace Composer\Downloader;
|
namespace Composer\Downloader;
|
||||||
|
|
||||||
use Composer\IO\IOInterface;
|
|
||||||
use Composer\Config;
|
|
||||||
use Composer\Util\Filesystem;
|
|
||||||
use Composer\Util\ProcessExecutor;
|
|
||||||
use Composer\Package\PackageInterface;
|
use Composer\Package\PackageInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,14 +19,6 @@ use Composer\Package\PackageInterface;
|
||||||
*/
|
*/
|
||||||
class GitDownloader extends VcsDownloader
|
class GitDownloader extends VcsDownloader
|
||||||
{
|
{
|
||||||
private $config;
|
|
||||||
|
|
||||||
public function __construct(IOInterface $io, Config $config, ProcessExecutor $process = null, Filesystem $fs = null)
|
|
||||||
{
|
|
||||||
parent::__construct($io, $process, $fs);
|
|
||||||
$this->config = $config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -162,8 +150,11 @@ class GitDownloader extends VcsDownloader
|
||||||
$handler = array($this, 'outputHandler');
|
$handler = array($this, 'outputHandler');
|
||||||
|
|
||||||
// public github, autoswitch protocols
|
// public github, autoswitch protocols
|
||||||
if (preg_match('{^(?:https?|git)(://github.com/.*)}', $url, $match) && $this->config->has('github-protocols')) {
|
if (preg_match('{^(?:https?|git)(://github.com/.*)}', $url, $match)) {
|
||||||
$protocols = (array) $this->config->get('github-protocols');
|
$protocols = $this->config->get('github-protocols');
|
||||||
|
if (!is_array($protocols)) {
|
||||||
|
throw new \RuntimeException('Config value "github-protocols" must be an array, got '.gettype($protocols));
|
||||||
|
}
|
||||||
$messages = array();
|
$messages = array();
|
||||||
foreach ($protocols as $protocol) {
|
foreach ($protocols as $protocol) {
|
||||||
$url = $protocol . $match[1];
|
$url = $protocol . $match[1];
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
namespace Composer\Downloader;
|
namespace Composer\Downloader;
|
||||||
|
|
||||||
|
use Composer\Config;
|
||||||
use Composer\Package\PackageInterface;
|
use Composer\Package\PackageInterface;
|
||||||
use Composer\Package\Version\VersionParser;
|
use Composer\Package\Version\VersionParser;
|
||||||
use Composer\Util\ProcessExecutor;
|
use Composer\Util\ProcessExecutor;
|
||||||
|
@ -24,12 +25,14 @@ use Composer\Util\Filesystem;
|
||||||
abstract class VcsDownloader implements DownloaderInterface
|
abstract class VcsDownloader implements DownloaderInterface
|
||||||
{
|
{
|
||||||
protected $io;
|
protected $io;
|
||||||
|
protected $config;
|
||||||
protected $process;
|
protected $process;
|
||||||
protected $filesystem;
|
protected $filesystem;
|
||||||
|
|
||||||
public function __construct(IOInterface $io, ProcessExecutor $process = null, Filesystem $fs = null)
|
public function __construct(IOInterface $io, Config $config, ProcessExecutor $process = null, Filesystem $fs = null)
|
||||||
{
|
{
|
||||||
$this->io = $io;
|
$this->io = $io;
|
||||||
|
$this->config = $config;
|
||||||
$this->process = $process ?: new ProcessExecutor;
|
$this->process = $process ?: new ProcessExecutor;
|
||||||
$this->filesystem = $fs ?: new Filesystem;
|
$this->filesystem = $fs ?: new Filesystem;
|
||||||
}
|
}
|
||||||
|
|
|
@ -223,8 +223,8 @@ class Factory
|
||||||
{
|
{
|
||||||
$dm = new Downloader\DownloadManager();
|
$dm = new Downloader\DownloadManager();
|
||||||
$dm->setDownloader('git', new Downloader\GitDownloader($io, $config));
|
$dm->setDownloader('git', new Downloader\GitDownloader($io, $config));
|
||||||
$dm->setDownloader('svn', new Downloader\SvnDownloader($io));
|
$dm->setDownloader('svn', new Downloader\SvnDownloader($io, $config));
|
||||||
$dm->setDownloader('hg', new Downloader\HgDownloader($io));
|
$dm->setDownloader('hg', new Downloader\HgDownloader($io, $config));
|
||||||
$dm->setDownloader('zip', new Downloader\ZipDownloader($io));
|
$dm->setDownloader('zip', new Downloader\ZipDownloader($io));
|
||||||
$dm->setDownloader('tar', new Downloader\TarDownloader($io));
|
$dm->setDownloader('tar', new Downloader\TarDownloader($io));
|
||||||
$dm->setDownloader('phar', new Downloader\PharDownloader($io));
|
$dm->setDownloader('phar', new Downloader\PharDownloader($io));
|
||||||
|
|
|
@ -152,7 +152,7 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->will($this->returnValue(0));
|
->will($this->returnValue(0));
|
||||||
|
|
||||||
$config = new Config();
|
$config = new Config();
|
||||||
$config->merge(array('config' => array('github-protocols' => 'http')));
|
$config->merge(array('config' => array('github-protocols' => array('http'))));
|
||||||
|
|
||||||
$downloader = $this->getDownloaderMock(null, $config, $processExecutor);
|
$downloader = $this->getDownloaderMock(null, $config, $processExecutor);
|
||||||
$downloader->download($packageMock, 'composerPath');
|
$downloader->download($packageMock, 'composerPath');
|
||||||
|
|
|
@ -16,13 +16,14 @@ use Composer\Downloader\HgDownloader;
|
||||||
|
|
||||||
class HgDownloaderTest extends \PHPUnit_Framework_TestCase
|
class HgDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
protected function getDownloaderMock($io = null, $executor = null, $filesystem = null)
|
protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null)
|
||||||
{
|
{
|
||||||
$io = $io ?: $this->getMock('Composer\IO\IOInterface');
|
$io = $io ?: $this->getMock('Composer\IO\IOInterface');
|
||||||
|
$config = $config ?: $this->getMock('Composer\Config');
|
||||||
$executor = $executor ?: $this->getMock('Composer\Util\ProcessExecutor');
|
$executor = $executor ?: $this->getMock('Composer\Util\ProcessExecutor');
|
||||||
$filesystem = $filesystem ?: $this->getMock('Composer\Util\Filesystem');
|
$filesystem = $filesystem ?: $this->getMock('Composer\Util\Filesystem');
|
||||||
|
|
||||||
return new HgDownloader($io, $executor, $filesystem);
|
return new HgDownloader($io, $config, $executor, $filesystem);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,7 +56,7 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($this->equalTo($expectedGitCommand))
|
->with($this->equalTo($expectedGitCommand))
|
||||||
->will($this->returnValue(0));
|
->will($this->returnValue(0));
|
||||||
|
|
||||||
$downloader = $this->getDownloaderMock(null, $processExecutor);
|
$downloader = $this->getDownloaderMock(null, null, $processExecutor);
|
||||||
$downloader->download($packageMock, 'composerPath');
|
$downloader->download($packageMock, 'composerPath');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +96,7 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($this->equalTo($expectedUpdateCommand))
|
->with($this->equalTo($expectedUpdateCommand))
|
||||||
->will($this->returnValue(0));
|
->will($this->returnValue(0));
|
||||||
|
|
||||||
$downloader = $this->getDownloaderMock(null, $processExecutor);
|
$downloader = $this->getDownloaderMock(null, null, $processExecutor);
|
||||||
$downloader->update($packageMock, $packageMock, 'composerPath');
|
$downloader->update($packageMock, $packageMock, 'composerPath');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +115,7 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($this->equalTo('composerPath'))
|
->with($this->equalTo('composerPath'))
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
$downloader = $this->getDownloaderMock(null, $processExecutor, $filesystem);
|
$downloader = $this->getDownloaderMock(null, null, $processExecutor, $filesystem);
|
||||||
$downloader->remove($packageMock, 'composerPath');
|
$downloader->remove($packageMock, 'composerPath');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue