1
0
Fork 0

Add support for the new composer repository format

pull/536/head
Jordi Boggiano 2012-04-06 20:40:31 +02:00
parent b14366ed08
commit a476d1f97d
1 changed files with 30 additions and 13 deletions

View File

@ -46,20 +46,37 @@ class ComposerRepository extends ArrayRepository
{
parent::initialize();
$json = new JsonFile($this->url.'/packages.json', new RemoteFilesystem($this->io));
$packages = $json->read();
if (!$packages) {
throw new \UnexpectedValueException('Could not parse package list from the '.$this->url.' repository');
}
if (isset($packages['includes'])) {
$this->io->write('<error>Your version of composer is too old, please run `php composer.phar self-update` to update it.</error>');
exit(1);
}
$data = $json->read();
$loader = new ArrayLoader();
foreach ($packages as $data) {
foreach ($data['versions'] as $rev) {
$this->addPackage($loader->load($rev));
$this->loadRepository($loader, $data);
}
protected function loadRepository(ArrayLoader $loader, $data)
{
// legacy repo handling
if (!isset($data['packages']) && !isset($data['includes'])) {
foreach ($data as $pkg) {
foreach ($pkg['versions'] as $metadata) {
$this->addPackage($loader->load($metadata));
}
}
return;
}
if (isset($data['packages'])) {
foreach ($data['packages'] as $package => $versions) {
foreach ($versions as $version => $metadata) {
$this->addPackage($loader->load($metadata));
}
}
}
if (isset($data['includes'])) {
foreach ($data['includes'] as $include => $metadata) {
$json = new JsonFile($this->url.'/'.$include, new RemoteFilesystem($this->io));
$this->loadRepository($loader, $json->read());
}
}
}