Permalink
Browse files

* condensed ZipDumper

 * moved code to BaseDumper (hopefully easier re-use)
  • Loading branch information...
1 parent e36559c commit 863c4c1295cf11b4f4340d74edee6400e7b3fdf7 @till committed Jun 15, 2012
Showing with 37 additions and 20 deletions.
  1. +35 −2 src/Composer/Package/Dumper/BaseDumper.php
  2. +2 −18 src/Composer/Package/Dumper/ZipDumper.php
@@ -12,6 +12,9 @@
namespace Composer\Package\Dumper;
use Composer\Package\PackageInterface;
+use Composer\Util\ProcessExecutor;
+use Composer\Downloader\GitDownloader;
+use Composer\IO\NullIO;
/**
* @author Till Klampaeckel <till@php.net>
@@ -68,8 +71,9 @@ public function __construct($path = null)
if (!is_writable($path)) {
throw new \InvalidArgumentException("Not authorized to write to '{$path}'");
}
- $this->path = $path;
- $this->temp = sys_get_temp_dir();
+ $this->path = $path;
+ $this->process = new ProcessExecutor;
+ $this->temp = sys_get_temp_dir();
}
}
@@ -89,4 +93,33 @@ public function getFilename(PackageInterface $package, $extension)
);
return $fileName;
}
+
+ /**
+ * @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 string $fileName
+ * @param string $sourceRef
+ * @param string $workDir
+ */
+ protected function packageGit($fileName, $sourceRef, $workDir)
+ {
+ $command = sprintf(
+ 'git archive --format %s --output %s %s',
+ $this->format,
+ escapeshellarg(sprintf('%s/%s', $this->path, $fileName)),
+ $sourceRef
+ );
+ $this->process->execute($command, $output, $workDir);
+ }
}
@@ -15,8 +15,6 @@
use Composer\Package\Dumper\DumperInterface;
use Composer\Package\PackageInterface;
use Composer\Util\ProcessExecutor;
-use Composer\Downloader\GitDownloader;
-use Composer\IO\NullIO;
/**
* @author Till Klampaeckel <till@php.net>
@@ -39,23 +37,9 @@ public function dump(PackageInterface $package)
switch ($sourceType) {
case 'git':
- $downloader = new GitDownloader(
- new NullIO(),
- $process
- );
- $downloader->download($package, $workDir);
-
- $command = sprintf(
- 'git archive --format %s --output %s %s',
- $this->format,
- sprintf('%s/%s', $this->path, $fileName),
- $sourceRef
- );
-
- $process->execute($command, $output, $workDir);
-
+ $this->downloadGit($package, $process, $workDir);
+ $this->packageGit($fileName, $sourceRef, $workDir);
break;
-
default:
throw new \InvalidArgumentException("Unable to handle repos of type {$sourceType} currently");
}

0 comments on commit 863c4c1

Please sign in to comment.