ProjectInstaller.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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\Installer;
  12. use Composer\Package\PackageInterface;
  13. use Composer\Downloader\DownloadManager;
  14. use Composer\Repository\InstalledRepositoryInterface;
  15. /**
  16. * Project Installer is used to install a single package into a directory as
  17. * root project.
  18. *
  19. * @author Benjamin Eberlei <kontakt@beberlei.de>
  20. */
  21. class ProjectInstaller implements InstallerInterface
  22. {
  23. private $installPath;
  24. private $downloadManager;
  25. public function __construct($installPath, DownloadManager $dm)
  26. {
  27. $this->installPath = $installPath;
  28. $this->downloadManager = $dm;
  29. }
  30. /**
  31. * Decides if the installer supports the given type
  32. *
  33. * @param string $packageType
  34. * @return bool
  35. */
  36. public function supports($packageType)
  37. {
  38. return true;
  39. }
  40. /**
  41. * {@inheritDoc}
  42. */
  43. public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package)
  44. {
  45. return false;
  46. }
  47. /**
  48. * {@inheritDoc}
  49. */
  50. public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
  51. {
  52. $installPath = $this->installPath;
  53. if (file_exists($installPath)) {
  54. throw new \InvalidArgumentException("Project directory $installPath already exists.");
  55. }
  56. if (!file_exists(dirname($installPath))) {
  57. throw new \InvalidArgumentException("Project root " . dirname($installPath) . " does not exist.");
  58. }
  59. mkdir($installPath, 0777);
  60. $this->downloadManager->download($package, $installPath);
  61. }
  62. /**
  63. * {@inheritDoc}
  64. */
  65. public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
  66. {
  67. throw new \InvalidArgumentException("not supported");
  68. }
  69. /**
  70. * {@inheritDoc}
  71. */
  72. public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
  73. {
  74. throw new \InvalidArgumentException("not supported");
  75. }
  76. /**
  77. * Returns the installation path of a package
  78. *
  79. * @param PackageInterface $package
  80. * @return string path
  81. */
  82. public function getInstallPath(PackageInterface $package)
  83. {
  84. return $this->installPath;
  85. }
  86. }