1
0
Fork 0

Fix PEAR dependencies

pull/494/head
Jordi Boggiano 2012-03-23 17:10:58 +01:00
parent 53ede45acc
commit 7dfb2724cb
1 changed files with 24 additions and 2 deletions

View File

@ -23,6 +23,8 @@ use Composer\Downloader\TransportException;
*/ */
class PearRepository extends ArrayRepository class PearRepository extends ArrayRepository
{ {
private static $channelNames = array();
private $url; private $url;
private $channel; private $channel;
private $io; private $io;
@ -54,11 +56,12 @@ class PearRepository extends ArrayRepository
protected function fetchFromServer() protected function fetchFromServer()
{ {
if (!$this->channel) {
$channelXML = $this->requestXml($this->url . "/channel.xml"); $channelXML = $this->requestXml($this->url . "/channel.xml");
if (!$this->channel) {
$this->channel = $channelXML->getElementsByTagName("suggestedalias")->item(0)->nodeValue $this->channel = $channelXML->getElementsByTagName("suggestedalias")->item(0)->nodeValue
?: $channelXML->getElementsByTagName("name")->item(0)->nodeValue; ?: $channelXML->getElementsByTagName("name")->item(0)->nodeValue;
} }
self::$channelNames[$channelXML->getElementsByTagName("name")->item(0)->nodeValue] = $this->channel;
$categoryXML = $this->requestXml($this->url . "/rest/c/categories.xml"); $categoryXML = $this->requestXml($this->url . "/rest/c/categories.xml");
$categories = $categoryXML->getElementsByTagName("c"); $categories = $categoryXML->getElementsByTagName("c");
@ -177,7 +180,10 @@ class PearRepository extends ArrayRepository
foreach ($options as $key => $value) { foreach ($options as $key => $value) {
if (is_array($value)) { if (is_array($value)) {
$dataKey = $value['name']; $dataKey = $value['name'];
$data[$dataKey] = $this->parseVersion($value); if (false === strpos($dataKey, '/')) {
$dataKey = $this->getChannelShorthand($value['channel']).'/'.$dataKey;
}
$data['pear-'.$dataKey] = $this->parseVersion($value);
} }
} }
} elseif ('extension' == $name) { } elseif ('extension' == $name) {
@ -299,4 +305,20 @@ class PearRepository extends ArrayRepository
return $dom; return $dom;
} }
private function getChannelShorthand($url)
{
if (!isset(self::$channelNames[$url])) {
try {
$channelXML = $this->requestXml('http://'.$url."/channel.xml");
$shorthand = $channelXML->getElementsByTagName("suggestedalias")->item(0)->nodeValue
?: $channelXML->getElementsByTagName("name")->item(0)->nodeValue;
self::$channelNames[$url] = $shorthand;
} catch (\Exception $e) {
self::$channelNames[$url] = substr($url, 0, strpos($url, '.'));
}
}
return self::$channelNames[$url];
}
} }