NoopInstaller.php 2.2 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. * Does not install anything but marks packages installed in the repo
  16. *
  17. * Useful for dry runs
  18. *
  19. * @author Jordi Boggiano <j.boggiano@seld.be>
  20. */
  21. class NoopInstaller implements InstallerInterface
  22. {
  23. /**
  24. * {@inheritDoc}
  25. */
  26. public function supports($packageType)
  27. {
  28. return true;
  29. }
  30. /**
  31. * {@inheritDoc}
  32. */
  33. public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package)
  34. {
  35. return $repo->hasPackage($package);
  36. }
  37. /**
  38. * {@inheritDoc}
  39. */
  40. public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
  41. {
  42. if (!$repo->hasPackage($package)) {
  43. $repo->addPackage(clone $package);
  44. }
  45. }
  46. /**
  47. * {@inheritDoc}
  48. */
  49. public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
  50. {
  51. if (!$repo->hasPackage($initial)) {
  52. throw new \InvalidArgumentException('Package is not installed: '.$initial);
  53. }
  54. if (!$repo->hasPackage($target)) {
  55. $repo->addPackage(clone $target);
  56. }
  57. }
  58. /**
  59. * {@inheritDoc}
  60. */
  61. public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
  62. {
  63. if (!$repo->hasPackage($package)) {
  64. // TODO throw exception again here, when update is fixed and we don't have to remove+install (see #125)
  65. return;
  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. $targetDir = $package->getTargetDir();
  76. return $package->getPrettyName() . ($targetDir ? '/'.$targetDir : '');
  77. }
  78. }