|
@@ -12,8 +12,10 @@
|
|
|
|
|
|
namespace Composer\Repository;
|
|
|
|
|
|
+use Composer\IO\IOInterface;
|
|
|
use Composer\Package\Loader\ArrayLoader;
|
|
|
-use Composer\Util\StreamContextFactory;
|
|
|
+use Composer\Util\RemoteFilesystem;
|
|
|
+use Composer\Downloader\TransportException;
|
|
|
|
|
|
/**
|
|
|
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
|
@@ -23,9 +25,10 @@ class PearRepository extends ArrayRepository
|
|
|
{
|
|
|
private $url;
|
|
|
private $channel;
|
|
|
- private $streamContext;
|
|
|
+ private $io;
|
|
|
+ private $rfs;
|
|
|
|
|
|
- public function __construct(array $config)
|
|
|
+ public function __construct(array $config, IOInterface $io, RemoteFilesystem $rfs = null)
|
|
|
{
|
|
|
if (!preg_match('{^https?://}', $config['url'])) {
|
|
|
$config['url'] = 'http://'.$config['url'];
|
|
@@ -36,20 +39,17 @@ class PearRepository extends ArrayRepository
|
|
|
}
|
|
|
|
|
|
$this->url = rtrim($config['url'], '/');
|
|
|
-
|
|
|
$this->channel = !empty($config['channel']) ? $config['channel'] : null;
|
|
|
+ $this->io = $io;
|
|
|
+ $this->rfs = $rfs ?: new RemoteFilesystem($this->io);
|
|
|
}
|
|
|
|
|
|
protected function initialize()
|
|
|
{
|
|
|
parent::initialize();
|
|
|
|
|
|
- set_error_handler(function($severity, $message, $file, $line) {
|
|
|
- throw new \ErrorException($message, $severity, $severity, $file, $line);
|
|
|
- });
|
|
|
- $this->streamContext = StreamContextFactory::getContext();
|
|
|
+ $this->io->write('Initializing PEAR repository '.$this->url);
|
|
|
$this->fetchFromServer();
|
|
|
- restore_error_handler();
|
|
|
}
|
|
|
|
|
|
protected function fetchFromServer()
|
|
@@ -68,7 +68,7 @@ class PearRepository extends ArrayRepository
|
|
|
try {
|
|
|
$packagesLink = str_replace("info.xml", "packagesinfo.xml", $link);
|
|
|
$this->fetchPear2Packages($this->url . $packagesLink);
|
|
|
- } catch (\ErrorException $e) {
|
|
|
+ } catch (TransportException $e) {
|
|
|
if (false === strpos($e->getMessage(), '404')) {
|
|
|
throw $e;
|
|
|
}
|
|
@@ -81,7 +81,7 @@ class PearRepository extends ArrayRepository
|
|
|
|
|
|
/**
|
|
|
* @param string $categoryLink
|
|
|
- * @throws ErrorException
|
|
|
+ * @throws TransportException
|
|
|
* @throws InvalidArgumentException
|
|
|
*/
|
|
|
private function fetchPearPackages($categoryLink)
|
|
@@ -99,7 +99,7 @@ class PearRepository extends ArrayRepository
|
|
|
|
|
|
try {
|
|
|
$releasesXML = $this->requestXml($allReleasesLink);
|
|
|
- } catch (\ErrorException $e) {
|
|
|
+ } catch (TransportException $e) {
|
|
|
if (strpos($e->getMessage(), '404')) {
|
|
|
continue;
|
|
|
}
|
|
@@ -120,8 +120,8 @@ class PearRepository extends ArrayRepository
|
|
|
);
|
|
|
|
|
|
try {
|
|
|
- $deps = file_get_contents($releaseLink . "/deps.".$pearVersion.".txt", false, $this->streamContext);
|
|
|
- } catch (\ErrorException $e) {
|
|
|
+ $deps = $this->rfs->getContents($this->url, $releaseLink . "/deps.".$pearVersion.".txt", false);
|
|
|
+ } catch (TransportException $e) {
|
|
|
if (strpos($e->getMessage(), '404')) {
|
|
|
continue;
|
|
|
}
|
|
@@ -226,6 +226,7 @@ class PearRepository extends ArrayRepository
|
|
|
{
|
|
|
$loader = new ArrayLoader();
|
|
|
$packagesXml = $this->requestXml($packagesLink);
|
|
|
+
|
|
|
$informations = $packagesXml->getElementsByTagName('pi');
|
|
|
foreach ($informations as $information) {
|
|
|
$package = $information->getElementsByTagName('p')->item(0);
|
|
@@ -289,7 +290,7 @@ class PearRepository extends ArrayRepository
|
|
|
*/
|
|
|
private function requestXml($url)
|
|
|
{
|
|
|
- $content = file_get_contents($url, false, $this->streamContext);
|
|
|
+ $content = $this->rfs->getContents($this->url, $url, false);
|
|
|
if (!$content) {
|
|
|
throw new \UnexpectedValueException('The PEAR channel at '.$url.' did not respond.');
|
|
|
}
|