From 7dfb2724cb7d1a8352555d3b573c14e5af3d7545 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 23 Mar 2012 17:10:58 +0100 Subject: [PATCH] Fix PEAR dependencies --- src/Composer/Repository/PearRepository.php | 26 ++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index 8b48d2db5..a2229251c 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -23,6 +23,8 @@ use Composer\Downloader\TransportException; */ class PearRepository extends ArrayRepository { + private static $channelNames = array(); + private $url; private $channel; private $io; @@ -54,11 +56,12 @@ class PearRepository extends ArrayRepository protected function fetchFromServer() { + $channelXML = $this->requestXml($this->url . "/channel.xml"); if (!$this->channel) { - $channelXML = $this->requestXml($this->url . "/channel.xml"); $this->channel = $channelXML->getElementsByTagName("suggestedalias")->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"); $categories = $categoryXML->getElementsByTagName("c"); @@ -177,7 +180,10 @@ class PearRepository extends ArrayRepository foreach ($options as $key => $value) { if (is_array($value)) { $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) { @@ -299,4 +305,20 @@ class PearRepository extends ArrayRepository 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]; + } }