MetapackageInstaller.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 download(PackageInterface $package, PackageInterface $prevPackage = null)
  39. {
  40. // noop
  41. }
  42. /**
  43. * {@inheritDoc}
  44. */
  45. public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
  46. {
  47. $repo->addPackage(clone $package);
  48. }
  49. /**
  50. * {@inheritDoc}
  51. */
  52. public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
  53. {
  54. if (!$repo->hasPackage($initial)) {
  55. throw new \InvalidArgumentException('Package is not installed: '.$initial);
  56. }
  57. $repo->removePackage($initial);
  58. $repo->addPackage(clone $target);
  59. }
  60. /**
  61. * {@inheritDoc}
  62. */
  63. public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
  64. {
  65. if (!$repo->hasPackage($package)) {
  66. throw new \InvalidArgumentException('Package is not installed: '.$package);
  67. }
  68. $repo->removePackage($package);
  69. }
  70. /**
  71. * {@inheritDoc}
  72. */
  73. public function getInstallPath(PackageInterface $package)
  74. {
  75. return '';
  76. }
  77. }