Added suport for PEAR2 repositories.
parent
8123de2fea
commit
14adc0213e
|
@ -31,7 +31,7 @@ class PearRepository extends ArrayRepository
|
||||||
throw new \UnexpectedValueException('Invalid url given for PEAR repository: '.$config['url']);
|
throw new \UnexpectedValueException('Invalid url given for PEAR repository: '.$config['url']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->url = $config['url'];
|
$this->url = preg_replace('#^(.+)/+$#U', '$1', $config['url']);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function initialize()
|
protected function initialize()
|
||||||
|
@ -51,13 +51,29 @@ class PearRepository extends ArrayRepository
|
||||||
$categories = $categoryXML->getElementsByTagName("c");
|
$categories = $categoryXML->getElementsByTagName("c");
|
||||||
|
|
||||||
foreach ($categories as $category) {
|
foreach ($categories as $category) {
|
||||||
$categoryLink = $category->getAttribute("xlink:href");
|
$link = $category->getAttribute("xlink:href");
|
||||||
$categoryLink = str_replace("info.xml", "packages.xml", $categoryLink);
|
try {
|
||||||
if ('/' !== substr($categoryLink, 0, 1)) {
|
$packagesLink = str_replace("info.xml", "packagesinfo.xml", $link);
|
||||||
$categoryLink = '/' . $categoryLink;
|
$this->fetchPear2Repositories($this->url . '/' . $packagesLink);
|
||||||
|
} catch (\ErrorException $e) {
|
||||||
|
if (false === strpos($e->getMessage(), '404')) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
$categoryLink = str_replace("info.xml", "packages.xml", $link);
|
||||||
|
$this->fetchPearRepositories($this->url . '/' . $categoryLink);
|
||||||
}
|
}
|
||||||
$packagesXML = $this->requestXml($this->url . $categoryLink);
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $categoryLink
|
||||||
|
* @throws ErrorException
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
*/
|
||||||
|
private function fetchPearRepositories($categoryLink)
|
||||||
|
{
|
||||||
|
$packagesXML = $this->requestXml($categoryLink);
|
||||||
$packages = $packagesXML->getElementsByTagName('p');
|
$packages = $packagesXML->getElementsByTagName('p');
|
||||||
$loader = new ArrayLoader();
|
$loader = new ArrayLoader();
|
||||||
foreach ($packages as $package) {
|
foreach ($packages as $package) {
|
||||||
|
@ -98,26 +114,7 @@ class PearRepository extends ArrayRepository
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preg_match('((O:([0-9])+:"([^"]+)"))', $deps, $matches)) {
|
$packageData += $this->parseDependences($deps);
|
||||||
if (strlen($matches[3]) == $matches[2]) {
|
|
||||||
throw new \InvalidArgumentException("Invalid dependency data, it contains serialized objects.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$deps = unserialize($deps);
|
|
||||||
if (isset($deps['required']['package'])) {
|
|
||||||
|
|
||||||
if (isset($deps['required']['package']['name'])) {
|
|
||||||
$deps['required']['package'] = array($deps['required']['package']);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($deps['required']['package'] as $dependency) {
|
|
||||||
if (isset($dependency['min'])) {
|
|
||||||
$packageData['require'][$dependency['name']] = '>='.$dependency['min'];
|
|
||||||
} else {
|
|
||||||
$packageData['require'][$dependency['name']] = '>=0.0.0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->addPackage($loader->load($packageData));
|
$this->addPackage($loader->load($packageData));
|
||||||
|
@ -127,6 +124,128 @@ class PearRepository extends ArrayRepository
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @todo Improve dependences of pear packages.
|
||||||
|
* @param array $options
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function parseDependencesOptions(array $depsOptions)
|
||||||
|
{
|
||||||
|
$data = array();
|
||||||
|
foreach ($depsOptions as $name => $options) {
|
||||||
|
if ('php' == $name) {
|
||||||
|
$key = $name;
|
||||||
|
if (isset($options['min'])) {
|
||||||
|
$value = '>=' . $options['min'];
|
||||||
|
} else {
|
||||||
|
$value = '>=0.0.0';
|
||||||
|
}
|
||||||
|
$data[$key] = $value;
|
||||||
|
|
||||||
|
} elseif ('package' == $name) {
|
||||||
|
foreach ($options as $key => $value) {
|
||||||
|
$key = $value['name'];
|
||||||
|
if (isset($value['min'])) {
|
||||||
|
$value = '>=' . $value['min'];
|
||||||
|
} else {
|
||||||
|
$value = '>=0.0.0';
|
||||||
|
}
|
||||||
|
$data[$key] = $value;
|
||||||
|
}
|
||||||
|
} elseif ('extension' == $name) {
|
||||||
|
foreach ($options as $key => $value) {
|
||||||
|
$key = 'ext-' . $value['name'];
|
||||||
|
$value = '*';
|
||||||
|
$data[$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$data = array_filter($data);
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $deps
|
||||||
|
* @return array
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
*/
|
||||||
|
private function parseDependences($deps)
|
||||||
|
{
|
||||||
|
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 = (array) @unserialize($deps);
|
||||||
|
unset($deps['required']['pearinstaller']);
|
||||||
|
|
||||||
|
$depsData = array();
|
||||||
|
if (isset($deps['required'])) {
|
||||||
|
$depsData['require'] = $this->parseDependencesOptions($deps['required']);
|
||||||
|
} else {
|
||||||
|
$depsData['require'] = array('php' => '>=5.3.0');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($depsData['optional'])) {
|
||||||
|
$depsData['recommend'] = $this->parseDependencesOptions($depsData['optional']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $depsData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $packagesLink
|
||||||
|
* @return void
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
*/
|
||||||
|
private function fetchPear2Repositories($packagesLink)
|
||||||
|
{
|
||||||
|
$loader = new ArrayLoader();
|
||||||
|
$packagesXml = $this->requestXml($packagesLink);
|
||||||
|
$informations = $packagesXml->getElementsByTagName('pi');
|
||||||
|
foreach ($informations as $information) {
|
||||||
|
$package = $information->getElementsByTagName('p')->item(0);
|
||||||
|
|
||||||
|
$packageName = $package->getElementsByTagName('n')->item(0)->nodeValue;
|
||||||
|
$packageData = array(
|
||||||
|
'name' => $packageName,
|
||||||
|
'type' => 'library'
|
||||||
|
);
|
||||||
|
$packageKeys = array('l' => 'license', 'd' => 'description');
|
||||||
|
foreach ($packageKeys as $pear => $composer) {
|
||||||
|
if ($package->getElementsByTagName($pear)->length > 0
|
||||||
|
&& ($pear = $package->getElementsByTagName($pear)->item(0)->nodeValue)) {
|
||||||
|
$packageData[$composer] = $pear;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$depsData = $information->getElementsByTagName('deps')->item(0);
|
||||||
|
$depsData = $depsData->getElementsByTagName('d')->item(0);
|
||||||
|
$depsData = $this->parseDependences($depsData->nodeValue);
|
||||||
|
|
||||||
|
$revisions = $information->getElementsByTagName('a')->item(0);
|
||||||
|
$revisions = $revisions->getElementsByTagName('r');
|
||||||
|
$packageUrl = $this->url . '/get/' . $packageName;
|
||||||
|
foreach ($revisions as $revision) {
|
||||||
|
$version = $revision->getElementsByTagName('v')->item(0)->nodeValue;
|
||||||
|
$revisionData = array(
|
||||||
|
'dist' => array(
|
||||||
|
'type' => 'pear',
|
||||||
|
'url' => $packageUrl . '-' . $version . '.tgz'
|
||||||
|
),
|
||||||
|
'version' => $version
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->addPackage(
|
||||||
|
$loader->load($packageData + $revisionData + $depsData)
|
||||||
|
);
|
||||||
|
} catch (\UnexpectedValueException $e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue