Fix PEAR repository
parent
a263a3cb7d
commit
dcfe310cff
|
@ -16,6 +16,7 @@ use Composer\Package\MemoryPackage;
|
||||||
use Composer\Package\BasePackage;
|
use Composer\Package\BasePackage;
|
||||||
use Composer\Package\Link;
|
use Composer\Package\Link;
|
||||||
use Composer\Package\LinkConstraint\VersionConstraint;
|
use Composer\Package\LinkConstraint\VersionConstraint;
|
||||||
|
use Composer\Package\Loader\ArrayLoader;
|
||||||
use Composer\Json\JsonFile;
|
use Composer\Json\JsonFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,12 +27,14 @@ use Composer\Json\JsonFile;
|
||||||
class GitRepository extends ArrayRepository
|
class GitRepository extends ArrayRepository
|
||||||
{
|
{
|
||||||
protected $url;
|
protected $url;
|
||||||
protected $cacheDir;
|
|
||||||
|
|
||||||
public function __construct($url, $cacheDir)
|
public function __construct(array $url)
|
||||||
{
|
{
|
||||||
|
if (!filter_var($config['url'], FILTER_VALIDATE_URL)) {
|
||||||
|
throw new \UnexpectedValueException('Invalid url given for PEAR repository: '.$url);
|
||||||
|
}
|
||||||
|
|
||||||
$this->url = $url;
|
$this->url = $url;
|
||||||
$this->cacheDir = $cacheDir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function initialize()
|
protected function initialize()
|
||||||
|
@ -47,7 +50,7 @@ class GitRepository extends ArrayRepository
|
||||||
throw new \InvalidArgumentException('The repository at url '.$this->url.' does not contain a composer.json file.');
|
throw new \InvalidArgumentException('The repository at url '.$this->url.' does not contain a composer.json file.');
|
||||||
}
|
}
|
||||||
$json = new JsonFile($this->url.'/composer.json');
|
$json = new JsonFile($this->url.'/composer.json');
|
||||||
$fonfig = $json->read();
|
$config = $json->read();
|
||||||
if (!$config) {
|
if (!$config) {
|
||||||
throw new \UnexpectedValueException('Config file could not be parsed: '.$this->url.'/composer.json. Probably a JSON syntax error.');
|
throw new \UnexpectedValueException('Config file could not be parsed: '.$this->url.'/composer.json. Probably a JSON syntax error.');
|
||||||
}
|
}
|
||||||
|
@ -58,57 +61,9 @@ class GitRepository extends ArrayRepository
|
||||||
$this->createPackage($config);
|
$this->createPackage($config);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO code re-use
|
|
||||||
protected function createPackage($data)
|
protected function createPackage($data)
|
||||||
{
|
{
|
||||||
$version = BasePackage::parseVersion($data['version']);
|
$loader = new ArrayLoader($this->repositoryManager);
|
||||||
|
$this->addPackage($loader->load($data));
|
||||||
$package = new MemoryPackage($data['name'], $version['version'], $version['type']);
|
|
||||||
$package->setSourceType('git');
|
|
||||||
$package->setSourceUrl($this->url);
|
|
||||||
|
|
||||||
if (isset($data['target-dir'])) {
|
|
||||||
$package->setTargetDir($data['target-dir']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($data['license'])) {
|
|
||||||
$package->setLicense($data['license']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$links = array(
|
|
||||||
'require',
|
|
||||||
'conflict',
|
|
||||||
'provide',
|
|
||||||
'replace',
|
|
||||||
'recommend',
|
|
||||||
'suggest',
|
|
||||||
);
|
|
||||||
foreach ($links as $link) {
|
|
||||||
if (isset($data[$link])) {
|
|
||||||
$method = 'set'.$link.'s';
|
|
||||||
$package->{$method}($this->createLinks($data['name'], $link.'s', $data[$link]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($data['autoload'])) {
|
|
||||||
$package->setAutoload($data['autoload']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->addPackage($package);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO code re-use
|
|
||||||
protected function createLinks($name, $description, $linkSpecs)
|
|
||||||
{
|
|
||||||
$links = array();
|
|
||||||
foreach ($linkSpecs as $dep => $ver) {
|
|
||||||
preg_match('#^([>=<~]*)([\d.]+.*)$#', $ver, $match);
|
|
||||||
if (!$match[1]) {
|
|
||||||
$match[1] = '=';
|
|
||||||
}
|
|
||||||
$constraint = new VersionConstraint($match[1], $match[2]);
|
|
||||||
$links[] = new Link($name, $dep, $constraint, $description);
|
|
||||||
}
|
|
||||||
return $links;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ use Composer\Package\MemoryPackage;
|
||||||
use Composer\Package\BasePackage;
|
use Composer\Package\BasePackage;
|
||||||
use Composer\Package\Link;
|
use Composer\Package\Link;
|
||||||
use Composer\Package\LinkConstraint\VersionConstraint;
|
use Composer\Package\LinkConstraint\VersionConstraint;
|
||||||
|
use Composer\Package\Loader\ArrayLoader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||||
|
@ -24,16 +25,14 @@ use Composer\Package\LinkConstraint\VersionConstraint;
|
||||||
class PearRepository extends ArrayRepository
|
class PearRepository extends ArrayRepository
|
||||||
{
|
{
|
||||||
protected $url;
|
protected $url;
|
||||||
protected $cacheDir;
|
|
||||||
|
|
||||||
public function __construct($url, $cacheDir)
|
public function __construct(array $config)
|
||||||
{
|
{
|
||||||
if (!filter_var($url, FILTER_VALIDATE_URL)) {
|
if (!filter_var($config['url'], FILTER_VALIDATE_URL)) {
|
||||||
throw new \UnexpectedValueException('Invalid url given for PEAR repository: '.$url);
|
throw new \UnexpectedValueException('Invalid url given for PEAR repository: '.$config['url']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->url = $url;
|
$this->url = $config['url'];
|
||||||
$this->cacheDir = $cacheDir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function initialize()
|
protected function initialize()
|
||||||
|
@ -72,14 +71,14 @@ class PearRepository extends ArrayRepository
|
||||||
/* @var $release DOMElement */
|
/* @var $release DOMElement */
|
||||||
$pearVersion = $release->getElementsByTagName('v')->item(0)->nodeValue;
|
$pearVersion = $release->getElementsByTagName('v')->item(0)->nodeValue;
|
||||||
|
|
||||||
$version = BasePackage::parseVersion($pearVersion);
|
$packageData = array(
|
||||||
|
'name' => $packageName,
|
||||||
|
'type' => 'library',
|
||||||
|
'dist' => array('type' => 'pear', 'url' => $this->url.'/get/'.$packageName.'-'.$pearVersion.".tgz"),
|
||||||
|
'version' => $pearVersion,
|
||||||
|
);
|
||||||
|
|
||||||
$package = new MemoryPackage($packageName, $version['version'], $version['type']);
|
$deps = file_get_contents($releaseLink . "/deps.".$pearVersion.".txt");
|
||||||
$package->setDistType('pear');
|
|
||||||
$package->setDistUrl($this->url.'/get/'.$packageName.'-'.$pearVersion.".tgz");
|
|
||||||
|
|
||||||
$depsLink = $releaseLink . "/deps.".$pearVersion.".txt";
|
|
||||||
$deps = file_get_contents($depsLink);
|
|
||||||
if (preg_match('((O:([0-9])+:"([^"]+)"))', $deps, $matches)) {
|
if (preg_match('((O:([0-9])+:"([^"]+)"))', $deps, $matches)) {
|
||||||
if (strlen($matches[3]) == $matches[2]) {
|
if (strlen($matches[3]) == $matches[2]) {
|
||||||
throw new \InvalidArgumentException("Invalid dependency data, it contains serialized objects.");
|
throw new \InvalidArgumentException("Invalid dependency data, it contains serialized objects.");
|
||||||
|
@ -88,18 +87,22 @@ class PearRepository extends ArrayRepository
|
||||||
$deps = unserialize($deps);
|
$deps = unserialize($deps);
|
||||||
if (isset($deps['required']['package'])) {
|
if (isset($deps['required']['package'])) {
|
||||||
$requires = array();
|
$requires = array();
|
||||||
|
|
||||||
|
if (isset($deps['required']['package']['name'])) {
|
||||||
|
$deps['required']['package'] = array($deps['required']['package']);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($deps['required']['package'] as $dependency) {
|
foreach ($deps['required']['package'] as $dependency) {
|
||||||
if (isset($dependency['min'])) {
|
if (isset($dependency['min'])) {
|
||||||
$constraint = new VersionConstraint('>=', $dependency['min']);
|
$packageData['require'][$dependency['name']] = '>='.$dependency['min'];
|
||||||
} else {
|
} else {
|
||||||
$constraint = new VersionConstraint('>=', '0.0.0');
|
$packageData['require'][$dependency['name']] = '>=0.0.0';
|
||||||
}
|
}
|
||||||
$requires[] = new Link($packageName, $dependency['name'], $constraint, 'requires');
|
|
||||||
}
|
}
|
||||||
$package->setRequires($requires);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addPackage($package);
|
$loader = new ArrayLoader($this->repositoryManager);
|
||||||
|
$this->addPackage($loader->load($packageData));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue