MetapackageInstaller.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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\Repository\InstalledRepositoryInterface;
  13. use Composer\Package\PackageInterface;
  14. /**
  15. * Metapackage installation manager.
  16. *
  17. * @author Martin Hasoň <martin.hason@gmail.com>
  18. */
  19. class MetapackageInstaller implements InstallerInterface
  20. {
  21. /**
  22. * {@inheritDoc}
  23. */
  24. public function supports($packageType)
  25. {
  26. return $packageType === 'metapackage';
  27. }
  28. /**
  29. * {@inheritDoc}
  30. */
  31. public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package)
  32. {
  33. return $repo->hasPackage($package);
  34. }
  35. /**
  36. * {@inheritDoc}
  37. */
  38. public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
  39. {
  40. $repo->addPackage(clone $package);
  41. }
  42. /**
  43. * {@inheritDoc}
  44. */
  45. public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
  46. {
  47. if (!$repo->hasPackage($initial)) {
  48. throw new \InvalidArgumentException('Package is not installed: '.$initial);
  49. }
  50. $repo->removePackage($initial);
  51. $repo->addPackage(clone $target);
  52. }
  53. /**
  54. * {@inheritDoc}
  55. */
  56. public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
  57. {
  58. if (!$repo->hasPackage($package)) {
  59. throw new \InvalidArgumentException('Package is not installed: '.$package);
  60. }
  61. $repo->removePackage($package);
  62. }
  63. /**
  64. * {@inheritDoc}
  65. */
  66. public function getInstallPath(PackageInterface $package)
  67. {
  68. return '';
  69. }
  70. }