Fix pear & zip downloaders
parent
544067ced9
commit
d455eef82c
|
@ -18,8 +18,8 @@ $rm->setRepository('Packagist', new Repository\ComposerRepository('http://packag
|
|||
// initialize download manager
|
||||
$dm = new Downloader\DownloadManager($preferSource = false);
|
||||
$dm->setDownloader('git', new Downloader\GitDownloader());
|
||||
//$dm->setDownloader('pear', new Downloader\PearDownloader());
|
||||
//$dm->setDownloader('zip', new Downloader\ZipDownloader());
|
||||
$dm->setDownloader('pear', new Downloader\PearDownloader());
|
||||
$dm->setDownloader('zip', new Downloader\ZipDownloader());
|
||||
|
||||
// initialize installation manager
|
||||
$im = new Installer\InstallationManager();
|
||||
|
|
|
@ -20,9 +20,33 @@ use Composer\Package\PackageInterface;
|
|||
*/
|
||||
class PearDownloader implements DownloaderInterface
|
||||
{
|
||||
public function download(PackageInterface $package, $path, $url, $checksum = null)
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function download(PackageInterface $package, $path, $url, $checksum = null, $useSource = false)
|
||||
{
|
||||
$this->downloadTo($package, $url, $path, $checksum);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function update(PackageInterface $initial, PackageInterface $target, $path, $useSource = false)
|
||||
{
|
||||
// TODO rm old dir
|
||||
$this->downloadTo($package, $url, $path, $checksum);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function remove(PackageInterface $package, $path, $useSource = false)
|
||||
{
|
||||
echo 'rm -rf '.$path; // TODO
|
||||
}
|
||||
|
||||
private function downloadTo($package, $url, $targetPath, $checksum = null)
|
||||
{
|
||||
$targetPath = $path . "/" . $package->getName();
|
||||
if (!is_dir($targetPath)) {
|
||||
if (file_exists($targetPath)) {
|
||||
throw new \UnexpectedValueException($targetPath.' exists and is not a directory.');
|
||||
|
|
|
@ -19,13 +19,37 @@ use Composer\Package\PackageInterface;
|
|||
*/
|
||||
class ZipDownloader implements DownloaderInterface
|
||||
{
|
||||
public function download(PackageInterface $package, $path, $url, $checksum = null)
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function download(PackageInterface $package, $path, $url, $checksum = null, $useSource = false)
|
||||
{
|
||||
$this->downloadTo($url, $path, $checksum);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function update(PackageInterface $initial, PackageInterface $target, $path, $useSource = false)
|
||||
{
|
||||
// TODO rm old dir
|
||||
$this->downloadTo($url, $path, $checksum);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function remove(PackageInterface $package, $path, $useSource = false)
|
||||
{
|
||||
echo 'rm -rf '.$path; // TODO
|
||||
}
|
||||
|
||||
private function downloadTo($url, $targetPath, $checksum = null)
|
||||
{
|
||||
if (!class_exists('ZipArchive')) {
|
||||
throw new \UnexpectedValueException('You need the zip extension enabled to use the ZipDownloader');
|
||||
}
|
||||
|
||||
$targetPath = $path . "/" . $package->getName();
|
||||
if (!is_dir($targetPath)) {
|
||||
if (file_exists($targetPath)) {
|
||||
throw new \UnexpectedValueException($targetPath.' exists and is not a directory.');
|
||||
|
@ -40,19 +64,18 @@ class ZipDownloader implements DownloaderInterface
|
|||
copy($url, $zipName);
|
||||
|
||||
if (!file_exists($zipName)) {
|
||||
throw new \UnexpectedValueException($path.' could not be saved into '.$zipName.', make sure the'
|
||||
throw new \UnexpectedValueException($targetPath.' could not be saved into '.$zipName.', make sure the'
|
||||
.' directory is writable and you have internet connectivity.');
|
||||
}
|
||||
|
||||
if ($checksum && hash_file('sha1', $zipName) !== $checksum) {
|
||||
throw new \UnexpectedValueException('The checksum verification failed for the '.$package->getName().' archive (downloaded from '.$url.'). Installation aborted.');
|
||||
throw new \UnexpectedValueException('The checksum verification failed for the '.basename($path).' archive (downloaded from '.$url.'). Installation aborted.');
|
||||
}
|
||||
|
||||
$zipArchive = new \ZipArchive();
|
||||
|
||||
echo 'Unpacking archive'.PHP_EOL;
|
||||
if (true === ($retval = $zipArchive->open($zipName))) {
|
||||
$targetPath = $path.'/'.$package->getName();
|
||||
$zipArchive->extractTo($targetPath);
|
||||
$zipArchive->close();
|
||||
echo 'Cleaning up'.PHP_EOL;
|
||||
|
|
Loading…
Reference in New Issue