Remove code duplication, add support for searchUrl

main
Jordi Boggiano 11 years ago
parent c54de4b72f
commit 095852933e

@ -36,6 +36,7 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository
protected $rfs; protected $rfs;
protected $cache; protected $cache;
protected $notifyUrl; protected $notifyUrl;
protected $searchUrl;
protected $hasProviders = false; protected $hasProviders = false;
protected $providersUrl; protected $providersUrl;
protected $providerListing; protected $providerListing;
@ -332,27 +333,17 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository
$data = $this->fetchFile($jsonUrl, 'packages.json'); $data = $this->fetchFile($jsonUrl, 'packages.json');
// TODO remove this BC notify_batch support
if (!empty($data['notify_batch'])) {
$notifyBatchUrl = $data['notify_batch'];
}
if (!empty($data['notify-batch'])) { if (!empty($data['notify-batch'])) {
$notifyBatchUrl = $data['notify-batch']; $this->notifyUrl = $this->canonicalizeUrl($data['notify-batch']);
} } elseif (!empty($data['notify_batch'])) {
if (!empty($notifyBatchUrl)) { // TODO remove this BC notify_batch support
if ('/' === $notifyBatchUrl[0]) { $this->notifyUrl = $this->canonicalizeUrl($data['notify_batch']);
$this->notifyUrl = preg_replace('{(https?://[^/]+).*}i', '$1' . $notifyBatchUrl, $this->url); } elseif (!empty($data['notify'])) {
} else { $this->notifyUrl = $this->canonicalizeUrl($data['notify']);
$this->notifyUrl = $notifyBatchUrl;
}
} }
if (!$this->notifyUrl && !empty($data['notify'])) { if (!empty($data['search'])) {
if ('/' === $data['notify'][0]) { $this->searchUrl = $this->canonicalizeUrl($data['search']);
$this->notifyUrl = preg_replace('{(https?://[^/]+).*}i', '$1' . $data['notify'], $this->url);
} else {
$this->notifyUrl = $data['notify'];
}
} }
if ($this->allowSslDowngrade) { if ($this->allowSslDowngrade) {
@ -360,11 +351,7 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository
} }
if (!empty($data['providers-url'])) { if (!empty($data['providers-url'])) {
if ('/' === $data['providers-url'][0]) { $this->providersUrl = $this->canonicalizeUrl($data['providers-url']);
$this->providersUrl = preg_replace('{(https?://[^/]+).*}i', '$1' . $data['providers-url'], $this->url);
} else {
$this->providersUrl = $data['providers-url'];
}
$this->hasProviders = true; $this->hasProviders = true;
} }
@ -375,6 +362,15 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository
return $this->rootData = $data; return $this->rootData = $data;
} }
protected function canonicalizeUrl($url)
{
if ('/' === $url[0]) {
return preg_replace('{(https?://[^/]+).*}i', '$1' . $url, $this->url);
}
return $url;
}
protected function loadDataFromServer() protected function loadDataFromServer()
{ {
$data = $this->loadRootServerFile(); $data = $this->loadRootServerFile();

Loading…
Cancel
Save