From 38680998ed18943276fedd830422c7736715d8b5 Mon Sep 17 00:00:00 2001 From: Beau Simensen Date: Wed, 14 Mar 2012 18:44:27 -0700 Subject: [PATCH] Remove the RemoteFilesystem factory and document GitHubDriver->GitDriver fallback. --- src/Composer/Downloader/ArchiveDownloader.php | 1 - src/Composer/Repository/Vcs/GitHubDriver.php | 13 +++++++++---- src/Composer/Repository/Vcs/VcsDriver.php | 13 +++++-------- .../Test/Repository/Vcs/GitHubDriverTest.php | 10 +++------- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/Composer/Downloader/ArchiveDownloader.php b/src/Composer/Downloader/ArchiveDownloader.php index 07d418bed..8e921a3e4 100644 --- a/src/Composer/Downloader/ArchiveDownloader.php +++ b/src/Composer/Downloader/ArchiveDownloader.php @@ -15,7 +15,6 @@ namespace Composer\Downloader; use Composer\IO\IOInterface; use Composer\Package\PackageInterface; use Composer\Util\Filesystem; -use Composer\Util\RemoteFilesystem; /** * Base downloader for archives diff --git a/src/Composer/Repository/Vcs/GitHubDriver.php b/src/Composer/Repository/Vcs/GitHubDriver.php index 6566d2b22..95701ddd6 100644 --- a/src/Composer/Repository/Vcs/GitHubDriver.php +++ b/src/Composer/Repository/Vcs/GitHubDriver.php @@ -6,6 +6,7 @@ use Composer\Downloader\TransportException; use Composer\Json\JsonFile; use Composer\IO\IOInterface; use Composer\Util\ProcessExecutor; +use Composer\Util\RemoteFilesystem; /** * @author Jordi Boggiano @@ -33,15 +34,15 @@ class GitHubDriver extends VcsDriver * @param string $url * @param IOInterface $io * @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); $this->owner = $match[1]; $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: $this->isPrivate = true; 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->generateSshUrl(), $this->io, $this->process, - $this->remoteFilesystemFactory + $this->remoteFilesystem ); $this->gitDriver->initialize(); return; diff --git a/src/Composer/Repository/Vcs/VcsDriver.php b/src/Composer/Repository/Vcs/VcsDriver.php index c2f65a7d8..99c705c50 100644 --- a/src/Composer/Repository/Vcs/VcsDriver.php +++ b/src/Composer/Repository/Vcs/VcsDriver.php @@ -27,7 +27,7 @@ abstract class VcsDriver implements VcsDriverInterface protected $url; protected $io; protected $process; - protected $remoteFilesystemFactory; + protected $remoteFilesystem; /** * Constructor. @@ -35,16 +35,14 @@ abstract class VcsDriver implements VcsDriverInterface * @param string $url The URL * @param IOInterface $io The IO instance * @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->io = $io; $this->process = $process ?: new ProcessExecutor; - $this->remoteFilesystemFactory = $remoteFilesystemFactory ?: function() use ($io) { - return new RemoteFilesystem($io); - }; + $this->remoteFilesystem = $remoteFilesystem ?: new RemoteFilesystem($io); } /** @@ -85,8 +83,7 @@ abstract class VcsDriver implements VcsDriverInterface */ protected function getContents($url) { - $rfs = call_user_func($this->remoteFilesystemFactory); - return $rfs->getContents($this->url, $url, false); + return $this->remoteFilesystem->getContents($this->url, $url, false); } protected static function isLocalUrl($url) diff --git a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php index 96506185c..c410b5ab5 100644 --- a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php @@ -61,7 +61,7 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase ->with($this->equalTo($repoUrl), $this->equalTo($repoApiUrl), $this->equalTo(false)) ->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(); $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)) ->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(); $this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha)); @@ -192,9 +190,7 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase ->method('splitLines') ->will($this->returnValue(array(' upstream/HEAD -> upstream/test_master'))); - $gitHubDriver = new GitHubDriver($repoUrl, $io, $process, function() use ($remoteFilesystem) { - return $remoteFilesystem; - }); + $gitHubDriver = new GitHubDriver($repoUrl, $io, $process, $remoteFilesystem); $gitHubDriver->initialize(); $this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());