* Jordi Boggiano * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Composer\Repository; use Composer\Package\Loader\ArrayLoader; use Composer\Package\LinkConstraint\VersionConstraint; use Composer\Json\JsonFile; /** * @author Jordi Boggiano */ class ComposerRepository extends ArrayRepository { protected $url; protected $packages; public function __construct($url) { $url = rtrim($url, '/'); if (!filter_var($url, FILTER_VALIDATE_URL)) { throw new \UnexpectedValueException('Invalid url given for Composer repository: '.$url); } $this->url = $url; } protected function initialize() { parent::initialize(); $json = new JsonFile($this->url.'/packages.json'); $packages = $json->read(); if (!$packages) { throw new \UnexpectedValueException('Could not parse package list from the '.$this->url.' repository'); } $loader = new ArrayLoader($this->repositoryManager); foreach ($packages as $data) { foreach ($data['versions'] as $rev) { $this->addPackage($loader->load($rev)); } } } }