Permalink
Browse files

* refactored downloading:

   * removed download*() methods
   * added dep on Composer\Factory to setup a DownloadManager instance
  • Loading branch information...
1 parent 1f41da8 commit b6f5d308b83d84528335f5bf49e958f124fc6160 @till committed Jun 25, 2012
@@ -17,6 +17,7 @@
use Composer\Downloader\HgDownloader;
use Composer\Downloader\SvnDownloader;
use Composer\IO\NullIO;
+use Composer\Factory;
/**
* @author Till Klampaeckel <till@php.net>
@@ -85,6 +86,16 @@ public function __construct($path = null, ProcessExecutor $process = null)
}
/**
+ * @return \Composer\Downloader\DownloadManager
+ */
+ public function getDownloadManager()
+ {
+ $factory = new Factory;
+ $dm = $factory->createDownloadManager(new NullIO());
+ return $dm;
+ }
+
+ /**
* @param \Composer\Package\PackageInterface $package
* @param string $extension
*
@@ -100,39 +111,10 @@ public function getFilename(PackageInterface $package, $extension)
/**
* @param \Composer\Package\PackageInterface $package
- * @param string $workDir
- */
- protected function downloadGit(PackageInterface $package, $workDir)
- {
- $downloader = new GitDownloader(
- new NullIO(),
- $this->process
- );
- $downloader->download($package, $workDir);
- }
-
- /**
- * @param \Composer\Package\PackageInterface $package
- * @param string $workDir
+ *
+ * @return string
+ * @throws \RuntimeException
*/
- protected function downloadHg(PackageInterface $package, $workDir)
- {
- $downloader = new HgDownloader(
- new NullIO(),
- $this->process
- );
- $downloader->download($package, $workDir);
- }
-
- protected function downloadSvn(PackageInterface $package, $workDir)
- {
- $downloader = new SvnDownloader(
- new NullIO(),
- $this->process
- );
- $downloader->download($package, $workDir);
- }
-
protected function getAndEnsureWorkDirectory(PackageInterface $package)
{
$workDir = sprintf('%s/%s/%s', $this->temp, $this->format, $package->getName());
@@ -23,6 +23,10 @@ class TarDumper extends BaseDumper
{
protected $format = 'tar';
+ /**
+ * @param \Composer\Package\PackageInterface $package
+ * @throws \InvalidArgumentException
+ */
public function dump(PackageInterface $package)
{
$workDir = $this->getAndEnsureWorkDirectory($package);
@@ -31,18 +35,18 @@ public function dump(PackageInterface $package)
$sourceType = $package->getSourceType();
$sourceRef = $package->getSourceReference();
+ $dm = $this->getDownloadManager();
+ $dm->download($package, $workDir, true);
+
switch ($sourceType) {
case 'git':
- $this->downloadGit($package, $workDir);
$this->packageGit($fileName, $sourceRef, $workDir);
break;
case 'hg':
- $this->downloadHg($package, $workDir);
$this->packageHg($fileName, $sourceRef, $workDir);
break;
case 'svn':
$dir = $workDir . (substr($sourceRef, 0, 1) !== '/')?'/':'' . $sourceRef;
- $this->downloadSvn($package, $workDir);
$this->package($fileName, $dir, \Phar::TAR);
break;
default:
@@ -23,6 +23,10 @@ class ZipDumper extends BaseDumper
{
protected $format = 'zip';
+ /**
+ * @param \Composer\Package\PackageInterface $package
+ * @throws \InvalidArgumentException
+ */
public function dump(PackageInterface $package)
{
$workDir = $this->getAndEnsureWorkDirectory($package);
@@ -31,18 +35,18 @@ public function dump(PackageInterface $package)
$sourceType = $package->getSourceType();
$sourceRef = $package->getSourceReference();
+ $dm = $this->getDownloadManager();
+ $dm->download($package, $workDir, true);
+
switch ($sourceType) {
case 'git':
- $this->downloadGit($package, $workDir);
$this->packageGit($fileName, $sourceRef, $workDir);
break;
case 'hg':
- $this->downloadHg($package, $workDir);
$this->packageHg($fileName, $sourceRef, $workDir);
break;
case 'svn':
$dir = $workDir . (substr($sourceRef, 0, 1) !== '/')?'/':'' . $sourceRef;
- $this->downloadSvn($package, $workDir);
$this->package($fileName, $dir, \Phar::ZIP);
break;
default:

0 comments on commit b6f5d30

Please sign in to comment.