1
0
Fork 0

Refactored Composer class to be service container

pull/19/head
everzet 2011-09-25 21:00:26 +03:00
parent 0694f5217a
commit ef71836f30
1 changed files with 46 additions and 34 deletions

View File

@ -12,8 +12,11 @@
namespace Composer;
use Composer\Installer\InstallerInterface;
use Composer\Repository\RepositoryInterface;
use Composer\Package\PackageInterface;
use Composer\Package\PackageLock;
use Composer\Repository\RepositoryManager;
use Composer\Installer\InstallationManager;
use Composer\Downloader\DownloadManager;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
@ -23,51 +26,60 @@ class Composer
{
const VERSION = '1.0.0-DEV';
private $repositories = array();
private $installers = array();
private $package;
private $lock;
public function setInstaller($type, InstallerInterface $installer = null)
private $rm;
private $dm;
private $im;
public function setPackage(PackageInterface $package)
{
if (null === $installer) {
unset($this->installers[$type]);
return;
$this->package = $package;
}
$this->installers[$type] = $installer;
}
public function getInstaller($type)
public function getPackage()
{
if (!isset($this->installers[$type])) {
throw new \UnexpectedValueException('Unknown dependency type: '.$type);
return $this->package;
}
return $this->installers[$type];
}
public function setRepository($name, RepositoryInterface $repository = null)
public function setPackageLock($lock)
{
if (null === $repository) {
unset($this->repositories[$name]);
return;
$this->lock = $lock;
}
$this->repositories[$name] = $repository;
}
public function getRepository($name)
public function getPackageLock()
{
if (!isset($this->repositories[$name])) {
throw new \UnexpectedValueException('Unknown repository: '.$name);
return $this->lock;
}
return $this->repositories[$name];
}
public function getRepositories()
public function setRepositoryManager(RepositoryManager $manager)
{
return $this->repositories;
$this->rm = $manager;
}
public function getRepositoryManager()
{
return $this->rm;
}
public function setDownloadManager(DownloadManager $manager)
{
$this->dm = $manager;
}
public function getDownloadManager()
{
return $this->dm;
}
public function setInstallationManager(InstallationManager $manager)
{
$this->im = $manager;
}
public function getInstallationManager()
{
return $this->im;
}
}