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