2011-04-17 22:14:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Repository;
|
|
|
|
|
2011-09-20 21:34:06 +00:00
|
|
|
use Composer\Package\Loader\ArrayLoader;
|
2011-04-23 18:52:37 +00:00
|
|
|
use Composer\Package\LinkConstraint\VersionConstraint;
|
2011-10-01 13:01:33 +00:00
|
|
|
use Composer\Json\JsonFile;
|
2011-04-17 22:14:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*/
|
|
|
|
class ComposerRepository extends ArrayRepository
|
|
|
|
{
|
2011-09-20 21:34:06 +00:00
|
|
|
protected $url;
|
2011-04-17 22:14:44 +00:00
|
|
|
protected $packages;
|
|
|
|
|
|
|
|
public function __construct($url)
|
|
|
|
{
|
2011-09-20 21:34:06 +00:00
|
|
|
$url = rtrim($url, '/');
|
|
|
|
if (!filter_var($url, FILTER_VALIDATE_URL)) {
|
|
|
|
throw new \UnexpectedValueException('Invalid url given for Composer repository: '.$url);
|
|
|
|
}
|
|
|
|
|
2011-04-17 22:14:44 +00:00
|
|
|
$this->url = $url;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function initialize()
|
|
|
|
{
|
|
|
|
parent::initialize();
|
2011-10-01 13:01:33 +00:00
|
|
|
$json = new JsonFile($this->url.'/packages.json');
|
|
|
|
$packages = $json->read();
|
2011-04-17 22:14:44 +00:00
|
|
|
if (!$packages) {
|
2011-04-18 20:48:51 +00:00
|
|
|
throw new \UnexpectedValueException('Could not parse package list from the '.$this->url.' repository');
|
2011-04-17 22:14:44 +00:00
|
|
|
}
|
|
|
|
|
2011-10-29 05:43:26 +00:00
|
|
|
$loader = new ArrayLoader($this->repositoryManager);
|
2011-04-17 22:14:44 +00:00
|
|
|
foreach ($packages as $data) {
|
2011-10-29 05:43:26 +00:00
|
|
|
foreach ($data['versions'] as $rev) {
|
|
|
|
$this->addPackage($loader->load($rev));
|
|
|
|
}
|
2011-04-23 18:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-17 11:39:37 +00:00
|
|
|
}
|