Explorar o código

Remove the RemoteFilesystem factory and document GitHubDriver->GitDriver fallback.

Beau Simensen %!s(int64=13) %!d(string=hai) anos
pai
achega
38680998ed

+ 0 - 1
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

+ 9 - 4
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 <j.boggiano@seld.be>
@@ -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;

+ 5 - 8
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)

+ 3 - 7
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());