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;
|
|
|
|
|
2011-09-15 19:58:00 +00:00
|
|
|
use Composer\Downloader\DownloaderInterface;
|
2011-09-17 11:18:34 +00:00
|
|
|
use Composer\Installer\InstallerInterface;
|
2011-04-17 22:14:44 +00:00
|
|
|
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-06-28 18:42:02 +00:00
|
|
|
use Composer\Repository\PearRepository;
|
2011-04-17 22:14:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*/
|
|
|
|
class Composer
|
|
|
|
{
|
2011-09-14 12:57:40 +00:00
|
|
|
const VERSION = '1.0.0-DEV';
|
|
|
|
|
2011-04-17 22:14:44 +00:00
|
|
|
protected $repositories = array();
|
|
|
|
protected $downloaders = array();
|
|
|
|
protected $installers = array();
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->addRepository('Packagist', array('composer' => 'http://packagist.org'));
|
|
|
|
}
|
|
|
|
|
2011-09-15 19:58:00 +00:00
|
|
|
/**
|
|
|
|
* Add downloader for type
|
|
|
|
*
|
|
|
|
* @param string $type
|
|
|
|
* @param DownloaderInterface $downloader
|
|
|
|
*/
|
|
|
|
public function addDownloader($type, DownloaderInterface $downloader)
|
2011-04-17 22:14:44 +00:00
|
|
|
{
|
2011-09-14 14:01:54 +00:00
|
|
|
$type = strtolower($type);
|
2011-04-17 22:14:44 +00:00
|
|
|
$this->downloaders[$type] = $downloader;
|
|
|
|
}
|
|
|
|
|
2011-09-15 19:58:00 +00:00
|
|
|
/**
|
|
|
|
* Get type downloader
|
|
|
|
*
|
|
|
|
* @param string $type
|
|
|
|
*
|
|
|
|
* @return DownloaderInterface
|
|
|
|
*/
|
2011-04-17 22:14:44 +00:00
|
|
|
public function getDownloader($type)
|
|
|
|
{
|
2011-09-14 14:01:54 +00:00
|
|
|
$type = strtolower($type);
|
2011-04-17 22:14:44 +00:00
|
|
|
if (!isset($this->downloaders[$type])) {
|
|
|
|
throw new \UnexpectedValueException('Unknown source type: '.$type);
|
|
|
|
}
|
|
|
|
return $this->downloaders[$type];
|
|
|
|
}
|
|
|
|
|
2011-09-15 19:58:00 +00:00
|
|
|
/**
|
|
|
|
* Add installer for type
|
|
|
|
*
|
|
|
|
* @param string $type
|
|
|
|
* @param InstallerInterface $installer
|
|
|
|
*/
|
|
|
|
public function addInstaller($type, InstallerInterface $installer)
|
2011-04-17 22:14:44 +00:00
|
|
|
{
|
2011-09-14 14:01:54 +00:00
|
|
|
$type = strtolower($type);
|
2011-04-17 22:14:44 +00:00
|
|
|
$this->installers[$type] = $installer;
|
|
|
|
}
|
|
|
|
|
2011-09-15 19:58:00 +00:00
|
|
|
/**
|
|
|
|
* Get type installer
|
|
|
|
*
|
|
|
|
* @param string $type
|
|
|
|
*
|
|
|
|
* @return InstallerInterface
|
|
|
|
*/
|
2011-04-17 22:14:44 +00:00
|
|
|
public function getInstaller($type)
|
|
|
|
{
|
2011-09-14 14:01:54 +00:00
|
|
|
$type = strtolower($type);
|
2011-04-17 22:14:44 +00:00
|
|
|
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]);
|
|
|
|
}
|
2011-06-28 18:42:19 +00:00
|
|
|
if (is_array($spec) && count($spec) === 1) {
|
2011-06-07 22:14:50 +00:00
|
|
|
return $this->repositories[$name] = $this->createRepository($name, key($spec), current($spec));
|
2011-04-17 22:14:44 +00:00
|
|
|
}
|
2011-06-28 18:42:19 +00:00
|
|
|
throw new \UnexpectedValueException('Invalid repositories specification '.json_encode($spec).', should be: {"type": "url"}');
|
2011-04-17 22:14:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getRepositories()
|
|
|
|
{
|
|
|
|
return $this->repositories;
|
|
|
|
}
|
|
|
|
|
2011-06-07 22:14:50 +00:00
|
|
|
public function createRepository($name, $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-17 22:14:44 +00:00
|
|
|
case 'composer':
|
2011-06-06 09:06:59 +00:00
|
|
|
return new ComposerRepository($spec['url']);
|
2011-06-28 18:42:02 +00:00
|
|
|
|
2011-06-07 22:14:50 +00:00
|
|
|
case 'pear':
|
2011-06-28 18:42:02 +00:00
|
|
|
return new PearRepository($spec['url'], $name);
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new \UnexpectedValueException('Unknown repository type: '.$type.', could not create repository '.$name);
|
2011-04-17 22:14:44 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-17 11:18:34 +00:00
|
|
|
}
|