1
0
Fork 0

[pear-prefix] add a pear-{channel}/ prefix to PearRepository packages

pull/335/head
Igor Wiedler 2012-02-20 12:51:30 +01:00
parent 9ba0505751
commit 06f1ecf83a
1 changed files with 12 additions and 2 deletions

View File

@ -22,6 +22,7 @@ use Composer\Util\StreamContextFactory;
class PearRepository extends ArrayRepository
{
private $url;
private $channel;
private $streamContext;
public function __construct(array $config)
@ -29,11 +30,14 @@ class PearRepository extends ArrayRepository
if (!preg_match('{^https?://}', $config['url'])) {
$config['url'] = 'http://'.$config['url'];
}
if (!filter_var($config['url'], FILTER_VALIDATE_URL)) {
throw new \UnexpectedValueException('Invalid url given for PEAR repository: '.$config['url']);
}
$this->url = rtrim($config['url'], '/');
$this->channel = !empty($config['channel']) ? $config['channel'] : null;
}
protected function initialize()
@ -50,6 +54,12 @@ class PearRepository extends ArrayRepository
protected function fetchFromServer()
{
if (!$this->channel) {
$channelXML = $this->requestXml($this->url . "/channel.xml");
$this->channel = $channelXML->getElementsByTagName("suggestedalias")->item(0)->nodeValue
?: $channelXML->getElementsByTagName("name")->item(0)->nodeValue;
}
$categoryXML = $this->requestXml($this->url . "/rest/c/categories.xml");
$categories = $categoryXML->getElementsByTagName("c");
@ -80,7 +90,7 @@ class PearRepository extends ArrayRepository
$packages = $packagesXML->getElementsByTagName('p');
$loader = new ArrayLoader();
foreach ($packages as $package) {
$packageName = $package->nodeValue;
$packageName = 'pear-'.$this->channel.'/'.$package->nodeValue;
$packageLink = $package->getAttribute('xlink:href');
$releaseLink = $this->url . str_replace("/rest/p/", "/rest/r/", $packageLink);
@ -219,7 +229,7 @@ class PearRepository extends ArrayRepository
foreach ($informations as $information) {
$package = $information->getElementsByTagName('p')->item(0);
$packageName = $package->getElementsByTagName('n')->item(0)->nodeValue;
$packageName = 'pear-'.$this->channel.'/'.$package->getElementsByTagName('n')->item(0)->nodeValue;
$packageData = array(
'name' => $packageName,
'type' => 'library'