Rewrite PearRepository to implement PEAR Client/Server protocol itself, taking longer then pear remote-list, but at least showing ALL available versions, making arbitrary dependencies possible.
parent
8afc2ca694
commit
fa613cad19
|
@ -29,13 +29,9 @@ abstract class AbstractDownloader
|
|||
while (!feof($file)) {
|
||||
fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($file) {
|
||||
fclose($file);
|
||||
}
|
||||
if ($newf) {
|
||||
fclose($newf);
|
||||
}
|
||||
fclose($file);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,44 +25,67 @@ class PearRepository extends ArrayRepository
|
|||
private $name;
|
||||
private $url;
|
||||
|
||||
public function __construct($url, $name)
|
||||
public function __construct($url)
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->name = $name;
|
||||
|
||||
if (!filter_var($this->url, FILTER_VALIDATE_URL)) {
|
||||
throw new \UnexpectedValueException("Invalid url given for PEAR repository " . $name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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();
|
||||
|
||||
exec("pear remote-list -c ".escapeshellarg($this->name), $output, $return);
|
||||
set_error_handler(function($severity, $message, $file, $line) {
|
||||
throw new ErrorException($message, $severity, $severity, $file, $line);
|
||||
});
|
||||
try {
|
||||
$this->fetchFromServer();
|
||||
} catch(ErrorException $e) {
|
||||
|
||||
if ($return != 0) {
|
||||
throw new \BadMethodCallException("Could not execute pear channel-list, an error occured.");
|
||||
}
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
$headersDone = false;
|
||||
foreach ($output AS $line) {
|
||||
$parts = explode(" ", preg_replace('(\s{2,})', ' ', trim($line)));
|
||||
if (count($parts) != 2) {
|
||||
continue;
|
||||
}
|
||||
list($packageName, $pearVersion) = $parts;
|
||||
protected function fetchFromServer()
|
||||
{
|
||||
$categoryXML = $this->requestXml($this->url . "/rest/c/categories.xml");
|
||||
$categories = $categoryXML->getElementsByTagName("c");
|
||||
|
||||
if (!$headersDone) {
|
||||
if ($packageName == "PACKAGE" && $pearVersion == "VERSION") {
|
||||
$headersDone = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
foreach ($categories as $category) {
|
||||
$categoryLink = $category->getAttribute("xlink:href");
|
||||
$categoryLink = str_replace("info.xml", "packages.xml", $categoryLink);
|
||||
$packagesXML = $this->requestXml($this->url . $categoryLink);
|
||||
|
||||
if ($pearVersion == "-n/a-") {
|
||||
continue; // Preferred stability is set to a level that this package can't fullfil.
|
||||
}
|
||||
$packages = $packagesXML->getElementsByTagName('p');
|
||||
foreach ($packages as $package) {
|
||||
$packageName = $package->nodeValue;
|
||||
|
||||
$packageLink = $package->getAttribute('xlink:href');
|
||||
$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) {
|
||||
/* @var $release DOMElement */
|
||||
$pearVersion = $release->getElementsByTagName('v')->item(0)->nodeValue;
|
||||
|
||||
$version = BasePackage::parseVersion($pearVersion);
|
||||
|
||||
|
@ -70,7 +93,24 @@ class PearRepository extends ArrayRepository
|
|||
$package->setSourceType('pear');
|
||||
$package->setSourceUrl($this->url.'/get/'.$packageName.'-'.$pearVersion.".tgz");
|
||||
|
||||
$depsLink = $releaseLink . "/deps.".$pearVersion.".txt";
|
||||
$deps = file_get_contents($depsLink);
|
||||
if (preg_match('((O:([0-9])+:"([^"]+)"))', $deps, $matches)) {
|
||||
if (strlen($matches[3]) == $matches[2]) {
|
||||
throw new \InvalidArgumentException("Invalid dependency data, it contains serialized objects.");
|
||||
}
|
||||
}
|
||||
$deps = unserialize($deps);
|
||||
if (isset($deps['required']['package'])) {
|
||||
foreach ($deps['required']['package'] as $dependency) {
|
||||
$requires[$dependency['name']] = $dependency['min'];
|
||||
}
|
||||
$package->setRequires($requires);
|
||||
}
|
||||
|
||||
$this->addPackage($package);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue