2011-06-07 22:14:50 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Downloader;
|
|
|
|
|
|
|
|
use Composer\Package\PackageInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
2011-06-28 18:42:02 +00:00
|
|
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
2011-06-07 22:14:50 +00:00
|
|
|
*/
|
2011-06-28 18:42:02 +00:00
|
|
|
class PearDownloader
|
2011-06-07 22:14:50 +00:00
|
|
|
{
|
|
|
|
public function download(PackageInterface $package, $path)
|
|
|
|
{
|
2011-06-28 18:42:02 +00:00
|
|
|
$targetPath = $path . "/" . $package->getName();
|
|
|
|
if (!is_dir($targetPath)) {
|
|
|
|
if (file_exists($targetPath)) {
|
|
|
|
throw new \UnexpectedValueException($targetPath.' exists and is not a directory.');
|
2011-06-07 22:14:50 +00:00
|
|
|
}
|
2011-06-28 18:42:02 +00:00
|
|
|
if (!mkdir($targetPath, 0777, true)) {
|
|
|
|
throw new \UnexpectedValueException($targetPath.' does not exist and could not be created.');
|
2011-06-07 22:14:50 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-08 20:06:57 +00:00
|
|
|
|
2011-06-28 18:42:02 +00:00
|
|
|
$cwd = getcwd();
|
|
|
|
chdir($targetPath);
|
|
|
|
|
|
|
|
$source = $package->getSourceUrl();
|
|
|
|
$tarName = basename($source);
|
2011-06-07 22:14:50 +00:00
|
|
|
|
2011-06-28 18:42:02 +00:00
|
|
|
echo 'Downloading '.$source.' to '.$targetPath.'/'.$tarName.PHP_EOL;
|
|
|
|
copy($package->getSourceUrl(), './'.$tarName);
|
|
|
|
|
|
|
|
if (!file_exists($tarName)) {
|
|
|
|
throw new \UnexpectedValueException($package->getName().' could not be saved into '.$tarName.', make sure the'
|
2011-06-07 22:14:50 +00:00
|
|
|
.' directory is writable and you have internet connectivity.');
|
|
|
|
}
|
2011-06-28 00:19:52 +00:00
|
|
|
|
2011-06-28 18:42:02 +00:00
|
|
|
echo 'Unpacking archive'.PHP_EOL;
|
|
|
|
exec('tar -xzf "'.escapeshellarg($tarName).'"');
|
|
|
|
|
|
|
|
echo 'Cleaning up'.PHP_EOL;
|
|
|
|
unlink('./'.$tarName);
|
|
|
|
@unlink('./package.sig');
|
|
|
|
@unlink('./package.xml');
|
|
|
|
if (list($dir) = glob('./'.$package->getName().'-*', GLOB_ONLYDIR)) {
|
|
|
|
foreach (array_merge(glob($dir.'/.*'), glob($dir.'/*')) as $file) {
|
|
|
|
if (trim(basename($file), '.')) {
|
|
|
|
rename($file, './'.basename($file));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rmdir($dir);
|
|
|
|
}
|
2011-06-07 22:14:50 +00:00
|
|
|
chdir($cwd);
|
|
|
|
}
|
|
|
|
}
|