Remove the RemoteFilesystem factory and document GitHubDriver->GitDriver fallback.
parent
1e9cb6bac8
commit
38680998ed
|
@ -15,7 +15,6 @@ namespace Composer\Downloader;
|
||||||
use Composer\IO\IOInterface;
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Package\PackageInterface;
|
use Composer\Package\PackageInterface;
|
||||||
use Composer\Util\Filesystem;
|
use Composer\Util\Filesystem;
|
||||||
use Composer\Util\RemoteFilesystem;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base downloader for archives
|
* Base downloader for archives
|
||||||
|
|
|
@ -6,6 +6,7 @@ use Composer\Downloader\TransportException;
|
||||||
use Composer\Json\JsonFile;
|
use Composer\Json\JsonFile;
|
||||||
use Composer\IO\IOInterface;
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Util\ProcessExecutor;
|
use Composer\Util\ProcessExecutor;
|
||||||
|
use Composer\Util\RemoteFilesystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
@ -33,15 +34,15 @@ class GitHubDriver extends VcsDriver
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @param IOInterface $io
|
* @param IOInterface $io
|
||||||
* @param ProcessExecutor $process
|
* @param ProcessExecutor $process
|
||||||
* @param callable $remoteFilesystemFactory
|
* @param RemoteFilesystem $remoteFilesystem
|
||||||
*/
|
*/
|
||||||
public function __construct($url, IOInterface $io, ProcessExecutor $process = null, $remoteFilesystemFactory = null)
|
public function __construct($url, IOInterface $io, ProcessExecutor $process = null, RemoteFilesystem $remoteFilesystem = null)
|
||||||
{
|
{
|
||||||
preg_match('#^(?:https?|git)://github\.com/([^/]+)/(.+?)(?:\.git)?$#', $url, $match);
|
preg_match('#^(?:https?|git)://github\.com/([^/]+)/(.+?)(?:\.git)?$#', $url, $match);
|
||||||
$this->owner = $match[1];
|
$this->owner = $match[1];
|
||||||
$this->repository = $match[2];
|
$this->repository = $match[2];
|
||||||
|
|
||||||
parent::__construct($url, $io, $process, $remoteFilesystemFactory);
|
parent::__construct($url, $io, $process, $remoteFilesystem);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -212,11 +213,15 @@ class GitHubDriver extends VcsDriver
|
||||||
case 404:
|
case 404:
|
||||||
$this->isPrivate = true;
|
$this->isPrivate = true;
|
||||||
if (!$this->io->isInteractive()) {
|
if (!$this->io->isInteractive()) {
|
||||||
|
// If this repository may be private (hard to say for sure,
|
||||||
|
// GitHub returns 404 for private repositories) and we
|
||||||
|
// cannot ask for authentication credentials (because we
|
||||||
|
// are not interactive) then we fallback to GitDriver.
|
||||||
$this->gitDriver = new GitDriver(
|
$this->gitDriver = new GitDriver(
|
||||||
$this->generateSshUrl(),
|
$this->generateSshUrl(),
|
||||||
$this->io,
|
$this->io,
|
||||||
$this->process,
|
$this->process,
|
||||||
$this->remoteFilesystemFactory
|
$this->remoteFilesystem
|
||||||
);
|
);
|
||||||
$this->gitDriver->initialize();
|
$this->gitDriver->initialize();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -27,7 +27,7 @@ abstract class VcsDriver implements VcsDriverInterface
|
||||||
protected $url;
|
protected $url;
|
||||||
protected $io;
|
protected $io;
|
||||||
protected $process;
|
protected $process;
|
||||||
protected $remoteFilesystemFactory;
|
protected $remoteFilesystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
@ -35,16 +35,14 @@ abstract class VcsDriver implements VcsDriverInterface
|
||||||
* @param string $url The URL
|
* @param string $url The URL
|
||||||
* @param IOInterface $io The IO instance
|
* @param IOInterface $io The IO instance
|
||||||
* @param ProcessExecutor $process Process instance, injectable for mocking
|
* @param ProcessExecutor $process Process instance, injectable for mocking
|
||||||
* @param callable $remoteFilesystemFactory Remote Filesystem factory, injectable for mocking
|
* @param callable $remoteFilesystem Remote Filesystem, injectable for mocking
|
||||||
*/
|
*/
|
||||||
public function __construct($url, IOInterface $io, ProcessExecutor $process = null, $remoteFilesystemFactory = null)
|
public function __construct($url, IOInterface $io, ProcessExecutor $process = null, $remoteFilesystem = null)
|
||||||
{
|
{
|
||||||
$this->url = $url;
|
$this->url = $url;
|
||||||
$this->io = $io;
|
$this->io = $io;
|
||||||
$this->process = $process ?: new ProcessExecutor;
|
$this->process = $process ?: new ProcessExecutor;
|
||||||
$this->remoteFilesystemFactory = $remoteFilesystemFactory ?: function() use ($io) {
|
$this->remoteFilesystem = $remoteFilesystem ?: new RemoteFilesystem($io);
|
||||||
return new RemoteFilesystem($io);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,8 +83,7 @@ abstract class VcsDriver implements VcsDriverInterface
|
||||||
*/
|
*/
|
||||||
protected function getContents($url)
|
protected function getContents($url)
|
||||||
{
|
{
|
||||||
$rfs = call_user_func($this->remoteFilesystemFactory);
|
return $this->remoteFilesystem->getContents($this->url, $url, false);
|
||||||
return $rfs->getContents($this->url, $url, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function isLocalUrl($url)
|
protected static function isLocalUrl($url)
|
||||||
|
|
|
@ -61,7 +61,7 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($this->equalTo($repoUrl), $this->equalTo($repoApiUrl), $this->equalTo(false))
|
->with($this->equalTo($repoUrl), $this->equalTo($repoApiUrl), $this->equalTo(false))
|
||||||
->will($this->returnValue('{"master_branch": "test_master"}'));
|
->will($this->returnValue('{"master_branch": "test_master"}'));
|
||||||
|
|
||||||
$gitHubDriver = new GitHubDriver($repoUrl, $io, null, function() use ($remoteFilesystem) { return $remoteFilesystem; });
|
$gitHubDriver = new GitHubDriver($repoUrl, $io, null, $remoteFilesystem);
|
||||||
$gitHubDriver->initialize();
|
$gitHubDriver->initialize();
|
||||||
$this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
|
$this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
|
||||||
|
|
||||||
|
@ -109,9 +109,7 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($this->equalTo($repoUrl), $this->equalTo($repoApiUrl), $this->equalTo(false))
|
->with($this->equalTo($repoUrl), $this->equalTo($repoApiUrl), $this->equalTo(false))
|
||||||
->will($this->returnValue('{"master_branch": "test_master"}'));
|
->will($this->returnValue('{"master_branch": "test_master"}'));
|
||||||
|
|
||||||
$gitHubDriver = new GitHubDriver($repoUrl, $io, null, function() use ($remoteFilesystem) {
|
$gitHubDriver = new GitHubDriver($repoUrl, $io, null, $remoteFilesystem);
|
||||||
return $remoteFilesystem;
|
|
||||||
});
|
|
||||||
$gitHubDriver->initialize();
|
$gitHubDriver->initialize();
|
||||||
$this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
|
$this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
|
||||||
|
|
||||||
|
@ -192,9 +190,7 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
|
||||||
->method('splitLines')
|
->method('splitLines')
|
||||||
->will($this->returnValue(array(' upstream/HEAD -> upstream/test_master')));
|
->will($this->returnValue(array(' upstream/HEAD -> upstream/test_master')));
|
||||||
|
|
||||||
$gitHubDriver = new GitHubDriver($repoUrl, $io, $process, function() use ($remoteFilesystem) {
|
$gitHubDriver = new GitHubDriver($repoUrl, $io, $process, $remoteFilesystem);
|
||||||
return $remoteFilesystem;
|
|
||||||
});
|
|
||||||
$gitHubDriver->initialize();
|
$gitHubDriver->initialize();
|
||||||
|
|
||||||
$this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());
|
$this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());
|
||||||
|
|
Loading…
Reference in New Issue