NoopInstaller.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. $repo->removePackage($initial);
  55. if (!$repo->hasPackage($target)) {
  56. $repo->addPackage(clone $target);
  57. }
  58. }
  59. /**
  60. * {@inheritDoc}
  61. */
  62. public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
  63. {
  64. if (!$repo->hasPackage($package)) {
  65. throw new \InvalidArgumentException('Package is not installed: '.$package);
  66. }
  67. $repo->removePackage($package);
  68. }
  69. /**
  70. * {@inheritDoc}
  71. */
  72. public function getInstallPath(PackageInterface $package)
  73. {
  74. $targetDir = $package->getTargetDir();
  75. return $package->getPrettyName() . ($targetDir ? '/'.$targetDir : '');
  76. }
  77. }