1
0
Fork 0

Refactored downloader code and made packagist configuration flexible and validated.

pull/322/head
Benjamin Eberlei 2012-02-19 12:08:38 +01:00
parent bbf745f3e6
commit 1c67633c70
2 changed files with 10 additions and 14 deletions

View File

@ -17,8 +17,7 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Downloader\DownloadManager; use Composer\Factory;
use Composer\Downloader;
use Composer\Repository\ComposerRepository; use Composer\Repository\ComposerRepository;
use Composer\Installer\ProjectInstaller; use Composer\Installer\ProjectInstaller;
@ -82,9 +81,14 @@ EOT
if ($packagistUrl === null) { if ($packagistUrl === null) {
$sourceRepo = new ComposerRepository(array('url' => 'http://packagist.org')); $sourceRepo = new ComposerRepository(array('url' => 'http://packagist.org'));
} else { } else if (substr($packagistUrl, -5) === ".json") {
$sourceRepo = new FilesystemRepository($packagistUrl);
} else if (strpos($packagistUrl, 'http') === 0) {
$sourceRepo = new ComposerRepository(array('url' => $packagistUrl)); $sourceRepo = new ComposerRepository(array('url' => $packagistUrl));
} else {
throw new \InvalidArgumentException("Invalid Packagist Url given. Has to be a .json file or an http url.");
} }
$package = $sourceRepo->findPackage($packageName, $version); $package = $sourceRepo->findPackage($packageName, $version);
if (!$package) { if (!$package) {
throw new \InvalidArgumentException("Could not find package $packageName with version $version."); throw new \InvalidArgumentException("Could not find package $packageName with version $version.");
@ -106,16 +110,8 @@ EOT
protected function createDownloadManager(IOInterface $io) protected function createDownloadManager(IOInterface $io)
{ {
$dm = new Downloader\DownloadManager(); $factory = new Factory();
$dm->setDownloader('git', new Downloader\GitDownloader($io)); return $factory->createDownloadManager($io);
$dm->setDownloader('svn', new Downloader\SvnDownloader($io));
$dm->setDownloader('hg', new Downloader\HgDownloader($io));
$dm->setDownloader('pear', new Downloader\PearDownloader($io));
$dm->setDownloader('zip', new Downloader\ZipDownloader($io));
$dm->setDownloader('tar', new Downloader\TarDownloader($io));
$dm->setDownloader('phar', new Downloader\PharDownloader($io));
return $dm;
} }
} }

View File

@ -138,7 +138,7 @@ class Factory
$rm->addRepository(new Repository\ComposerRepository(array('url' => 'http://packagist.org'))); $rm->addRepository(new Repository\ComposerRepository(array('url' => 'http://packagist.org')));
} }
protected function createDownloadManager(IOInterface $io) public function createDownloadManager(IOInterface $io)
{ {
$dm = new Downloader\DownloadManager(); $dm = new Downloader\DownloadManager();
$dm->setDownloader('git', new Downloader\GitDownloader($io)); $dm->setDownloader('git', new Downloader\GitDownloader($io));