Composer.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer;
  12. use Composer\Installer\InstallerInterface;
  13. use Composer\Repository\RepositoryInterface;
  14. /**
  15. * @author Jordi Boggiano <j.boggiano@seld.be>
  16. * @author Konstantin Kudryashiv <ever.zet@gmail.com>
  17. */
  18. class Composer
  19. {
  20. const VERSION = '1.0.0-DEV';
  21. private $repositories = array();
  22. private $installers = array();
  23. public function setInstaller($type, InstallerInterface $installer = null)
  24. {
  25. if (null === $installer) {
  26. unset($this->installers[$type]);
  27. return;
  28. }
  29. $this->installers[$type] = $installer;
  30. }
  31. public function getInstaller($type)
  32. {
  33. if (!isset($this->installers[$type])) {
  34. throw new \UnexpectedValueException('Unknown dependency type: '.$type);
  35. }
  36. return $this->installers[$type];
  37. }
  38. public function setRepository($name, RepositoryInterface $repository = null)
  39. {
  40. if (null === $repository) {
  41. unset($this->repositories[$name]);
  42. return;
  43. }
  44. $this->repositories[$name] = $repository;
  45. }
  46. public function getRepository($name)
  47. {
  48. if (!isset($this->repositories[$name])) {
  49. throw new \UnexpectedValueException('Unknown repository: '.$name);
  50. }
  51. return $this->repositories[$name];
  52. }
  53. public function getRepositories()
  54. {
  55. return $this->repositories;
  56. }
  57. }