Refactored Composer class to be service container

main
everzet 13 years ago
parent 0694f5217a
commit ef71836f30

@ -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;
if (null === $installer) { private $im;
unset($this->installers[$type]);
return; public function setPackage(PackageInterface $package)
} {
$this->package = $package;
}
$this->installers[$type] = $installer; public function getPackage()
{
return $this->package;
} }
public function getInstaller($type) public function setPackageLock($lock)
{ {
if (!isset($this->installers[$type])) { $this->lock = $lock;
throw new \UnexpectedValueException('Unknown dependency type: '.$type); }
}
return $this->installers[$type]; public function getPackageLock()
{
return $this->lock;
} }
public function setRepository($name, RepositoryInterface $repository = null) public function setRepositoryManager(RepositoryManager $manager)
{ {
if (null === $repository) { $this->rm = $manager;
unset($this->repositories[$name]); }
return; public function getRepositoryManager()
} {
return $this->rm;
}
$this->repositories[$name] = $repository; public function setDownloadManager(DownloadManager $manager)
{
$this->dm = $manager;
} }
public function getRepository($name) public function getDownloadManager()
{ {
if (!isset($this->repositories[$name])) { return $this->dm;
throw new \UnexpectedValueException('Unknown repository: '.$name); }
}
return $this->repositories[$name]; public function setInstallationManager(InstallationManager $manager)
{
$this->im = $manager;
} }
public function getRepositories() public function getInstallationManager()
{ {
return $this->repositories; return $this->im;
} }
} }

Loading…
Cancel
Save