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;
|
|
|
|
|
|
|
|
use Composer\Repository\ComposerRepository;
|
2011-04-21 08:24:19 +00:00
|
|
|
use Composer\Repository\PlatformRepository;
|
2011-06-06 09:06:59 +00:00
|
|
|
use Composer\Repository\GitRepository;
|
2011-04-17 22:14:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*/
|
|
|
|
class Composer
|
|
|
|
{
|
|
|
|
protected $repositories = array();
|
|
|
|
protected $downloaders = array();
|
|
|
|
protected $installers = array();
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->addRepository('Packagist', array('composer' => 'http://packagist.org'));
|
2011-04-21 08:24:19 +00:00
|
|
|
$this->addRepository('Platform', array('platform' => ''));
|
2011-04-17 22:14:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function addDownloader($type, $downloader)
|
|
|
|
{
|
|
|
|
$this->downloaders[$type] = $downloader;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDownloader($type)
|
|
|
|
{
|
|
|
|
if (!isset($this->downloaders[$type])) {
|
|
|
|
throw new \UnexpectedValueException('Unknown source type: '.$type);
|
|
|
|
}
|
|
|
|
return $this->downloaders[$type];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addInstaller($type, $installer)
|
|
|
|
{
|
|
|
|
$this->installers[$type] = $installer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getInstaller($type)
|
|
|
|
{
|
|
|
|
if (!isset($this->installers[$type])) {
|
|
|
|
throw new \UnexpectedValueException('Unknown dependency type: '.$type);
|
|
|
|
}
|
|
|
|
return $this->installers[$type];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addRepository($name, $spec)
|
|
|
|
{
|
|
|
|
if (null === $spec) {
|
|
|
|
unset($this->repositories[$name]);
|
|
|
|
}
|
|
|
|
if (is_array($spec) && count($spec)) {
|
|
|
|
return $this->repositories[$name] = $this->createRepository(key($spec), current($spec));
|
|
|
|
}
|
|
|
|
throw new \UnexpectedValueException('Invalid repositories specification '.var_export($spec, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRepositories()
|
|
|
|
{
|
|
|
|
return $this->repositories;
|
|
|
|
}
|
|
|
|
|
2011-06-06 09:06:59 +00:00
|
|
|
public function createRepository($type, $spec)
|
2011-04-17 22:14:44 +00:00
|
|
|
{
|
2011-06-06 09:06:59 +00:00
|
|
|
if (is_string($spec)) {
|
|
|
|
$spec = array('url' => $spec);
|
|
|
|
}
|
|
|
|
$spec['url'] = rtrim($spec['url'], '/');
|
2011-04-17 22:14:44 +00:00
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
case 'git-bare':
|
|
|
|
case 'git-multi':
|
|
|
|
throw new \Exception($type.' repositories not supported yet');
|
|
|
|
break;
|
|
|
|
|
2011-06-06 09:06:59 +00:00
|
|
|
case 'git':
|
|
|
|
return new GitRepository($spec['url']);
|
|
|
|
|
2011-04-21 08:24:19 +00:00
|
|
|
case 'platform':
|
|
|
|
return new PlatformRepository;
|
|
|
|
|
2011-04-17 22:14:44 +00:00
|
|
|
case 'composer':
|
2011-06-06 09:06:59 +00:00
|
|
|
return new ComposerRepository($spec['url']);
|
2011-04-17 22:14:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|