PluginInstaller.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\Composer;
  13. use Composer\Package\Package;
  14. use Composer\IO\IOInterface;
  15. use Composer\Repository\InstalledRepositoryInterface;
  16. use Composer\Package\PackageInterface;
  17. /**
  18. * Installer for plugin packages
  19. *
  20. * @author Jordi Boggiano <j.boggiano@seld.be>
  21. * @author Nils Adermann <naderman@naderman.de>
  22. */
  23. class PluginInstaller extends LibraryInstaller
  24. {
  25. private $installationManager;
  26. private static $classCounter = 0;
  27. /**
  28. * Initializes Plugin installer.
  29. *
  30. * @param IOInterface $io
  31. * @param Composer $composer
  32. * @param string $type
  33. */
  34. public function __construct(IOInterface $io, Composer $composer, $type = 'library')
  35. {
  36. parent::__construct($io, $composer, 'composer-plugin');
  37. $this->installationManager = $composer->getInstallationManager();
  38. }
  39. /**
  40. * {@inheritDoc}
  41. */
  42. public function supports($packageType)
  43. {
  44. return $packageType === 'composer-plugin' || $packageType === 'composer-installer';
  45. }
  46. /**
  47. * {@inheritDoc}
  48. */
  49. public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
  50. {
  51. $extra = $package->getExtra();
  52. if (empty($extra['class'])) {
  53. throw new \UnexpectedValueException('Error while installing '.$package->getPrettyName().', composer-plugin packages should have a class defined in their extra key to be usable.');
  54. }
  55. parent::install($repo, $package);
  56. $this->composer->getPluginManager()->registerPackage($package, true);
  57. }
  58. /**
  59. * {@inheritDoc}
  60. */
  61. public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
  62. {
  63. $extra = $target->getExtra();
  64. if (empty($extra['class'])) {
  65. throw new \UnexpectedValueException('Error while installing '.$target->getPrettyName().', composer-plugin packages should have a class defined in their extra key to be usable.');
  66. }
  67. parent::update($repo, $initial, $target);
  68. $this->composer->getPluginManager()->registerPackage($target, true);
  69. }
  70. }