Browse Source

Refactored Composer class to be service container

everzet 13 years ago
parent
commit
ef71836f30
1 changed files with 41 additions and 29 deletions
  1. 41 29
      src/Composer/Composer.php

+ 41 - 29
src/Composer/Composer.php

@@ -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)
-    {
-        if (null === $installer) {
-            unset($this->installers[$type]);
+    private $rm;
+    private $dm;
+    private $im;
 
-            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])) {
-            throw new \UnexpectedValueException('Unknown dependency type: '.$type);
-        }
+        $this->lock = $lock;
+    }
 
-        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) {
-            unset($this->repositories[$name]);
+        $this->rm = $manager;
+    }
 
-            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])) {
-            throw new \UnexpectedValueException('Unknown repository: '.$name);
-        }
+        return $this->dm;
+    }
 
-        return $this->repositories[$name];
+    public function setInstallationManager(InstallationManager $manager)
+    {
+        $this->im = $manager;
     }
 
-    public function getRepositories()
+    public function getInstallationManager()
     {
-        return $this->repositories;
+        return $this->im;
     }
 }