Builder.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace Fgm\Drupal\Composer;
  3. use Composer\Composer;
  4. use Composer\EventDispatcher\Event;
  5. use Composer\EventDispatcher\EventSubscriberInterface;
  6. use Composer\Installer\InstallerEvents;
  7. use Composer\Installer\PackageEvents;
  8. use Composer\IO\IOInterface;
  9. use Composer\Plugin\Capability\CommandProvider;
  10. use Composer\Plugin\Capable;
  11. use Composer\Plugin\PluginEvents;
  12. use Composer\Plugin\PluginInterface;
  13. use Composer\Script\ScriptEvents;
  14. use Doctrine\Common\Util\Debug;
  15. class Builder implements Capable, EventSubscriberInterface, PluginInterface {
  16. /**
  17. * @var IOInterface
  18. */
  19. protected $io;
  20. /**
  21. * Apply plugin modifications to Composer
  22. *
  23. * @param Composer $composer
  24. * @param IOInterface $io
  25. */
  26. public function activate(Composer $composer, IOInterface $io) {
  27. Debug::dump($composer);
  28. Debug::dump($io);
  29. $this->io = $io;
  30. }
  31. public function getCapabilities() {
  32. return [
  33. CommandProvider::class => Builder::class,
  34. ];
  35. }
  36. /**
  37. * For CommandProvider::class.
  38. */
  39. public function getCommands() {
  40. echo __METHOD__ . "\n";
  41. return [];
  42. }
  43. /**
  44. * Returns an array of event names this subscriber wants to listen to.
  45. *
  46. * The array keys are event names and the value can be:
  47. *
  48. * * The method name to call (priority defaults to 0)
  49. * * An array composed of the method name to call and the priority
  50. * * An array of arrays composed of the method names to call and respective
  51. * priorities, or 0 if unset
  52. *
  53. * For instance:
  54. *
  55. * * array('eventName' => 'methodName')
  56. * * array('eventName' => array('methodName', $priority))
  57. * * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
  58. *
  59. * @return array The event names to listen to
  60. */
  61. public static function getSubscribedEvents() {
  62. return [
  63. InstallerEvents::POST_DEPENDENCIES_SOLVING => 'onEvent',
  64. InstallerEvents::PRE_DEPENDENCIES_SOLVING => 'onEvent',
  65. PackageEvents::POST_PACKAGE_INSTALL => 'onEvent',
  66. PackageEvents::POST_PACKAGE_UNINSTALL => 'onEvent',
  67. PackageEvents::POST_PACKAGE_UPDATE => 'onEvent',
  68. PackageEvents::PRE_PACKAGE_INSTALL => 'onEvent',
  69. PackageEvents::PRE_PACKAGE_UNINSTALL => 'onEvent',
  70. PackageEvents::PRE_PACKAGE_UPDATE => 'onEvent',
  71. PluginEvents::COMMAND => 'onEvent',
  72. PluginEvents::INIT => 'onEvent',
  73. PluginEvents::PRE_FILE_DOWNLOAD => 'onEvent',
  74. ScriptEvents::POST_ARCHIVE_CMD => 'onEvent',
  75. ScriptEvents::POST_AUTOLOAD_DUMP => 'onEvent',
  76. ScriptEvents::POST_CREATE_PROJECT_CMD => 'onEvent',
  77. ScriptEvents::POST_INSTALL_CMD => 'onEvent',
  78. ScriptEvents::POST_PACKAGE_INSTALL => 'onEvent',
  79. ScriptEvents::POST_PACKAGE_UNINSTALL => 'onEvent',
  80. ScriptEvents::POST_PACKAGE_UPDATE => 'onEvent',
  81. ScriptEvents::POST_ROOT_PACKAGE_INSTALL => 'onEvent',
  82. ScriptEvents::POST_STATUS_CMD => 'onEvent',
  83. ScriptEvents::POST_UPDATE_CMD => 'onEvent',
  84. ScriptEvents::PRE_ARCHIVE_CMD => 'onEvent',
  85. ScriptEvents::PRE_AUTOLOAD_DUMP => 'onEvent',
  86. ScriptEvents::PRE_INSTALL_CMD => 'onEvent',
  87. ScriptEvents::PRE_PACKAGE_INSTALL => 'onEvent',
  88. ScriptEvents::PRE_PACKAGE_UNINSTALL => 'onEvent',
  89. ScriptEvents::PRE_PACKAGE_UPDATE => 'onEvent',
  90. ScriptEvents::PRE_STATUS_CMD => 'onEvent',
  91. ScriptEvents::PRE_UPDATE_CMD => 'onEvent',
  92. ];
  93. }
  94. public function onEvent(Event $event) {
  95. $this->io->write(Debug::dump($event, 2, false, false));
  96. }
  97. }