Fixes and improvements to the PEAR implementation
parent
75428d9ad1
commit
f272f66324
|
@ -15,6 +15,7 @@ namespace Composer;
|
|||
use Composer\Repository\ComposerRepository;
|
||||
use Composer\Repository\PlatformRepository;
|
||||
use Composer\Repository\GitRepository;
|
||||
use Composer\Repository\PearRepository;
|
||||
|
||||
/**
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
|
@ -94,8 +95,12 @@ class Composer
|
|||
|
||||
case 'composer':
|
||||
return new ComposerRepository($spec['url']);
|
||||
|
||||
case 'pear':
|
||||
return new Repository\PearRepository($spec['url'], isset($spec['name']) ? $spec['name'] : $name);
|
||||
return new PearRepository($spec['url'], $name);
|
||||
|
||||
default:
|
||||
throw new \UnexpectedValueException('Unknown repository type: '.$type.', could not create repository '.$name);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,32 +16,51 @@ use Composer\Package\PackageInterface;
|
|||
|
||||
/**
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*/
|
||||
class PearDownloader extends AbstractDownloader
|
||||
class PearDownloader
|
||||
{
|
||||
public function download(PackageInterface $package, $path)
|
||||
{
|
||||
$path = $path . "/" . $package->getName();
|
||||
if (!is_dir($path)) {
|
||||
if (file_exists($path)) {
|
||||
throw new \UnexpectedValueException($path.' exists and is not a directory.');
|
||||
$targetPath = $path . "/" . $package->getName();
|
||||
if (!is_dir($targetPath)) {
|
||||
if (file_exists($targetPath)) {
|
||||
throw new \UnexpectedValueException($targetPath.' exists and is not a directory.');
|
||||
}
|
||||
if (!mkdir($path, 0777, true)) {
|
||||
throw new \UnexpectedValueException($path.' does not exist and could not be created.');
|
||||
if (!mkdir($targetPath, 0777, true)) {
|
||||
throw new \UnexpectedValueException($targetPath.' does not exist and could not be created.');
|
||||
}
|
||||
}
|
||||
|
||||
$tmpName = tempnam(sys_get_temp_dir(), '');
|
||||
copy($package->getSourceUrl(), $tmpName);
|
||||
|
||||
if (!file_exists($tmpName)) {
|
||||
throw new \UnexpectedValueException($package->getName().' could not be saved into '.$tmpName.', make sure the'
|
||||
.' directory is writable and you have internet connectivity.');
|
||||
}
|
||||
|
||||
$cwd = getcwd();
|
||||
chdir($path);
|
||||
system('tar xzf '.escapeshellarg($tmpName));
|
||||
chdir($targetPath);
|
||||
|
||||
$source = $package->getSourceUrl();
|
||||
$tarName = basename($source);
|
||||
|
||||
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'
|
||||
.' directory is writable and you have internet connectivity.');
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
chdir($cwd);
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@ use Composer\Package\PackageInterface;
|
|||
/**
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*/
|
||||
class ZipDownloader extends AbstractDownloader
|
||||
class ZipDownloader
|
||||
{
|
||||
public function download(PackageInterface $package, $path)
|
||||
{
|
||||
|
|
|
@ -19,46 +19,30 @@ use Composer\Package\LinkConstraint\VersionConstraint;
|
|||
|
||||
/**
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*/
|
||||
class PearRepository extends ArrayRepository
|
||||
{
|
||||
private $name;
|
||||
private $url;
|
||||
|
||||
public function __construct($url)
|
||||
public function __construct($url, $name = '')
|
||||
{
|
||||
$this->url = $url;
|
||||
|
||||
if (!filter_var($this->url, FILTER_VALIDATE_URL)) {
|
||||
throw new \UnexpectedValueException("Invalid url given for PEAR repository " . $name);
|
||||
if (!filter_var($url, FILTER_VALIDATE_URL)) {
|
||||
throw new \UnexpectedValueException('Invalid url given for PEAR repository "'.$name.'": '.$url);
|
||||
}
|
||||
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @return DOMDocument
|
||||
*/
|
||||
private function requestXml($url)
|
||||
{
|
||||
$content = file_get_contents($url);
|
||||
$dom = new \DOMDocument('1.0', 'UTF-8');
|
||||
$dom->loadXML($content);
|
||||
|
||||
return $dom;
|
||||
}
|
||||
|
||||
protected function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
|
||||
set_error_handler(function($severity, $message, $file, $line) {
|
||||
throw new ErrorException($message, $severity, $severity, $file, $line);
|
||||
throw new \ErrorException($message, $severity, $severity, $file, $line);
|
||||
});
|
||||
try {
|
||||
$this->fetchFromServer();
|
||||
} catch(ErrorException $e) {
|
||||
|
||||
}
|
||||
$this->fetchFromServer();
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
|
@ -80,7 +64,7 @@ class PearRepository extends ArrayRepository
|
|||
$releaseLink = $this->url . str_replace("/rest/p/", "/rest/r/", $packageLink);
|
||||
$allReleasesLink = $releaseLink . "/allreleases2.xml";
|
||||
$releasesXML = $this->requestXml($allReleasesLink);
|
||||
|
||||
|
||||
$releases = $releasesXML->getElementsByTagName('r');
|
||||
|
||||
foreach ($releases as $release) {
|
||||
|
@ -102,8 +86,14 @@ class PearRepository extends ArrayRepository
|
|||
}
|
||||
$deps = unserialize($deps);
|
||||
if (isset($deps['required']['package'])) {
|
||||
$requires = array();
|
||||
foreach ($deps['required']['package'] as $dependency) {
|
||||
$requires[$dependency['name']] = $dependency['min'];
|
||||
if (isset($dependency['min'])) {
|
||||
$constraint = new VersionConstraint('>=', $dependency['min']);
|
||||
} else {
|
||||
$constraint = new VersionConstraint('>=', '0.0.0');
|
||||
}
|
||||
$requires[] = new Link($packageName, $dependency['name'], $constraint, 'requires');
|
||||
}
|
||||
$package->setRequires($requires);
|
||||
}
|
||||
|
@ -113,4 +103,20 @@ class PearRepository extends ArrayRepository
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @return DOMDocument
|
||||
*/
|
||||
private function requestXml($url)
|
||||
{
|
||||
$content = file_get_contents($url);
|
||||
if (!$content) {
|
||||
throw new \UnexpectedValueException('The PEAR channel at '.$url.' did not respond.');
|
||||
}
|
||||
$dom = new \DOMDocument('1.0', 'UTF-8');
|
||||
$dom->loadXML($content);
|
||||
|
||||
return $dom;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue