From a476d1f97dcd88bfb3c9fec44a72fe2e15151c2c Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 6 Apr 2012 20:40:31 +0200 Subject: [PATCH] Add support for the new composer repository format --- .../Repository/ComposerRepository.php | 43 +++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index 5a0c84de9..055c25f81 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -45,21 +45,38 @@ class ComposerRepository extends ArrayRepository protected function initialize() { 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('Your version of composer is too old, please run `php composer.phar self-update` to update it.'); - exit(1); - } + $json = new JsonFile($this->url.'/packages.json', new RemoteFilesystem($this->io)); + $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()); } } }