Remove PackageInterface dependency from DownloaderInterface
parent
30f6c05069
commit
c07c993e70
|
@ -94,14 +94,12 @@ class DownloadManager
|
|||
if (!($preferSource && $sourceType) && $distType) {
|
||||
$downloader = $this->getDownloader($distType);
|
||||
$downloader->download(
|
||||
$package, $targetDir,
|
||||
$package->getDistUrl(), $package->getDistSha1Checksum(),
|
||||
$preferSource
|
||||
$targetDir, $package->getDistUrl(), $package->getDistSha1Checksum(), $preferSource
|
||||
);
|
||||
$package->setInstallationSource('dist');
|
||||
} elseif ($sourceType) {
|
||||
$downloader = $this->getDownloader($sourceType);
|
||||
$downloader->download($package, $targetDir, $package->getSourceUrl(), $preferSource);
|
||||
$downloader->download($targetDir, $package->getSourceUrl(), null, $preferSource);
|
||||
$package->setInstallationSource('source');
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Package should have dist or source specified');
|
||||
|
@ -137,9 +135,15 @@ class DownloadManager
|
|||
$downloader = $this->getDownloader($initialType);
|
||||
|
||||
if ($initialType === $targetType) {
|
||||
$downloader->update($initial, $target, $targetDir, $useSource);
|
||||
if (!$useSource) {
|
||||
$downloader->update(
|
||||
$targetDir, $target->getDistUrl(), $target->getDistSha1Checksum(), $useSource
|
||||
);
|
||||
} else {
|
||||
$downloader->remove($initial, $targetDir, $useSource);
|
||||
$downloader->update($targetDir, $target->getSourceUrl(), null, $useSource);
|
||||
}
|
||||
} else {
|
||||
$downloader->remove($targetDir, $useSource);
|
||||
$this->download($target, $targetDir, $useSource);
|
||||
}
|
||||
}
|
||||
|
@ -166,6 +170,6 @@ class DownloadManager
|
|||
$downloader = $this->getDownloader($package->getSourceType());
|
||||
}
|
||||
|
||||
$downloader->remove($package, $targetDir, $useSource);
|
||||
$downloader->remove($targetDir, $useSource);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
|
||||
namespace Composer\Downloader;
|
||||
|
||||
use Composer\Package\PackageInterface;
|
||||
|
||||
/**
|
||||
* Downloader interface.
|
||||
*
|
||||
|
@ -24,30 +22,28 @@ interface DownloaderInterface
|
|||
/**
|
||||
* Downloads specific package into specific folder.
|
||||
*
|
||||
* @param PackageInterface $package package instance
|
||||
* @param string $path download path
|
||||
* @param string $url download url
|
||||
* @param string $checksum package checksum (for dists)
|
||||
* @param Boolean $useSource download as source
|
||||
*/
|
||||
function download(PackageInterface $package, $path, $url, $checksum = null, $useSource = false);
|
||||
function download($path, $url, $checksum = null, $useSource = false);
|
||||
|
||||
/**
|
||||
* Updates specific package in specific folder from initial to target version.
|
||||
*
|
||||
* @param PackageInterface $initial initial package
|
||||
* @param PackageInterface $target updated package
|
||||
* @param string $path download path
|
||||
* @param string $url download url
|
||||
* @param string $checksum package checksum (for dists)
|
||||
* @param Boolean $useSource download as source
|
||||
*/
|
||||
function update(PackageInterface $initial, PackageInterface $target, $path, $useSource = false);
|
||||
function update($path, $url, $checksum = null, $useSource = false);
|
||||
|
||||
/**
|
||||
* Removes specific package from specific folder.
|
||||
*
|
||||
* @param PackageInterface $package package instance
|
||||
* @param string $path download path
|
||||
* @param Boolean $useSource download as source
|
||||
*/
|
||||
function remove(PackageInterface $package, $path, $useSource = false);
|
||||
function remove($path, $useSource = false);
|
||||
}
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
|
||||
namespace Composer\Downloader;
|
||||
|
||||
use Composer\Package\PackageInterface;
|
||||
|
||||
/**
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*/
|
||||
|
@ -22,7 +20,7 @@ class GitDownloader implements DownloaderInterface
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function download(PackageInterface $package, $path, $url, $checksum = null, $useSource = false)
|
||||
public function download($path, $url, $checksum = null, $useSource = false)
|
||||
{
|
||||
system('git clone '.escapeshellarg($url).' -b master '.escapeshellarg($path));
|
||||
|
||||
|
@ -33,7 +31,7 @@ class GitDownloader implements DownloaderInterface
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function update(PackageInterface $initial, PackageInterface $target, $path, $useSource = false)
|
||||
public function update($path, $url, $checksum = null, $useSource = false)
|
||||
{
|
||||
$cwd = getcwd();
|
||||
chdir($path);
|
||||
|
@ -44,7 +42,7 @@ class GitDownloader implements DownloaderInterface
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function remove(PackageInterface $package, $path, $useSource = false)
|
||||
public function remove($path, $useSource = false)
|
||||
{
|
||||
echo 'rm -rf '.$path; // TODO
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
|||
$pearDownloader
|
||||
->expects($this->once())
|
||||
->method('download')
|
||||
->with($package, 'target_dir', 'dist_url', 'sha1', false);
|
||||
->with('target_dir', 'dist_url', 'sha1', false);
|
||||
|
||||
$manager = new DownloadManager();
|
||||
$manager->setDownloader('pear', $pearDownloader);
|
||||
|
@ -114,7 +114,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
|||
$pearDownloader
|
||||
->expects($this->once())
|
||||
->method('download')
|
||||
->with($package, 'target_dir', 'dist_url', 'sha1', false);
|
||||
->with('target_dir', 'dist_url', 'sha1', false);
|
||||
|
||||
$manager = new DownloadManager();
|
||||
$manager->setDownloader('pear', $pearDownloader);
|
||||
|
@ -148,7 +148,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
|||
$gitDownloader
|
||||
->expects($this->once())
|
||||
->method('download')
|
||||
->with($package, 'vendor/pkg', 'source_url', false);
|
||||
->with('vendor/pkg', 'source_url', null, false);
|
||||
|
||||
$manager = new DownloadManager();
|
||||
$manager->setDownloader('git', $gitDownloader);
|
||||
|
@ -182,7 +182,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
|||
$gitDownloader
|
||||
->expects($this->once())
|
||||
->method('download')
|
||||
->with($package, 'vendor/pkg', 'source_url', true);
|
||||
->with('vendor/pkg', 'source_url', null, true);
|
||||
|
||||
$manager = new DownloadManager();
|
||||
$manager->setDownloader('git', $gitDownloader);
|
||||
|
@ -221,7 +221,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
|||
$pearDownloader
|
||||
->expects($this->once())
|
||||
->method('download')
|
||||
->with($package, 'target_dir', 'dist_url', 'sha1', true);
|
||||
->with('target_dir', 'dist_url', 'sha1', true);
|
||||
|
||||
$manager = new DownloadManager();
|
||||
$manager->setDownloader('pear', $pearDownloader);
|
||||
|
@ -256,7 +256,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
|||
$gitDownloader
|
||||
->expects($this->once())
|
||||
->method('download')
|
||||
->with($package, 'vendor/pkg', 'source_url', true);
|
||||
->with('vendor/pkg', 'source_url', null, true);
|
||||
|
||||
$manager = new DownloadManager();
|
||||
$manager->setDownloader('git', $gitDownloader);
|
||||
|
@ -301,12 +301,20 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
|||
->expects($this->once())
|
||||
->method('getDistType')
|
||||
->will($this->returnValue('pear'));
|
||||
$target
|
||||
->expects($this->once())
|
||||
->method('getDistUrl')
|
||||
->will($this->returnValue('d_url'));
|
||||
$target
|
||||
->expects($this->once())
|
||||
->method('getDistSha1Checksum')
|
||||
->will($this->returnValue('sha'));
|
||||
|
||||
$pearDownloader = $this->createDownloaderMock();
|
||||
$pearDownloader
|
||||
->expects($this->once())
|
||||
->method('update')
|
||||
->with($initial, $target, 'vendor/bundles/FOS/UserBundle', false);
|
||||
->with('vendor/bundles/FOS/UserBundle', 'd_url', 'sha', false);
|
||||
|
||||
$manager = new DownloadManager();
|
||||
$manager->setDownloader('pear', $pearDownloader);
|
||||
|
@ -336,7 +344,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
|||
$pearDownloader
|
||||
->expects($this->once())
|
||||
->method('remove')
|
||||
->with($initial, 'vendor/bundles/FOS/UserBundle', false);
|
||||
->with('vendor/bundles/FOS/UserBundle', false);
|
||||
|
||||
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
||||
->setMethods(array('download'))
|
||||
|
@ -367,12 +375,16 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
|||
->expects($this->once())
|
||||
->method('getSourceType')
|
||||
->will($this->returnValue('svn'));
|
||||
$target
|
||||
->expects($this->once())
|
||||
->method('getSourceUrl')
|
||||
->will($this->returnValue('s_url'));
|
||||
|
||||
$svnDownloader = $this->createDownloaderMock();
|
||||
$svnDownloader
|
||||
->expects($this->once())
|
||||
->method('update')
|
||||
->with($initial, $target, 'vendor/pkg', true);
|
||||
->with('vendor/pkg', 's_url', null, true);
|
||||
|
||||
$manager = new DownloadManager();
|
||||
$manager->setDownloader('svn', $svnDownloader);
|
||||
|
@ -402,7 +414,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
|||
$svnDownloader
|
||||
->expects($this->once())
|
||||
->method('remove')
|
||||
->with($initial, 'vendor/pkg', true);
|
||||
->with('vendor/pkg', true);
|
||||
|
||||
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
||||
->setMethods(array('download'))
|
||||
|
@ -443,7 +455,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
|||
$pearDownloader
|
||||
->expects($this->once())
|
||||
->method('remove')
|
||||
->with($package, 'vendor/bundles/FOS/UserBundle');
|
||||
->with('vendor/bundles/FOS/UserBundle', false);
|
||||
|
||||
$manager = new DownloadManager();
|
||||
$manager->setDownloader('pear', $pearDownloader);
|
||||
|
@ -467,7 +479,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
|||
$svnDownloader
|
||||
->expects($this->once())
|
||||
->method('remove')
|
||||
->with($package, 'vendor/pkg');
|
||||
->with('vendor/pkg', true);
|
||||
|
||||
$manager = new DownloadManager();
|
||||
$manager->setDownloader('svn', $svnDownloader);
|
||||
|
|
Loading…
Reference in New Issue