1
0
Fork 0
composer/src/Composer/Repository/ComposerRepository.php

58 lines
1.6 KiB
PHP
Raw Normal View History

<?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;
use Composer\Package\LinkConstraint\VersionConstraint;
use Composer\Json\JsonFile;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class ComposerRepository extends ArrayRepository
{
2011-09-20 21:34:06 +00:00
protected $url;
protected $packages;
2011-12-03 11:43:38 +00:00
public function __construct(array $config)
{
2011-12-09 22:37:52 +00:00
if (!preg_match('{^\w+://}', $config['url'])) {
// assume http as the default protocol
2011-12-03 11:43:38 +00:00
$config['url'] = 'http://'.$config['url'];
}
$config['url'] = rtrim($config['url'], '/');
if (!filter_var($config['url'], FILTER_VALIDATE_URL)) {
throw new \UnexpectedValueException('Invalid url given for Composer repository: '.$config['url']);
2011-09-20 21:34:06 +00:00
}
2011-12-03 11:43:38 +00:00
$this->url = $config['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));
}
}
}
2011-09-17 11:39:37 +00:00
}