Builder.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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\PackageEvent;
  8. use Composer\Installer\PackageEvents;
  9. use Composer\IO\IOInterface;
  10. use Composer\Plugin\Capability\Capability;
  11. use Composer\Plugin\Capability\CommandProvider;
  12. use Composer\Plugin\Capable;
  13. use Composer\Plugin\CommandEvent;
  14. use Composer\Plugin\PluginEvents;
  15. use Composer\Plugin\PluginInterface;
  16. use Composer\Script\Event as ScriptEvent;
  17. use Composer\Script\ScriptEvents;
  18. use Symfony\Component\Console\Input\ArgvInput;
  19. use Symfony\Component\Console\Output\ConsoleOutput;
  20. class Builder implements Capable, Capability, EventSubscriberInterface, PluginInterface {
  21. /**
  22. * @var \Composer\Composer
  23. */
  24. protected $composer;
  25. /**
  26. * @var \Composer\IO\IOInterface
  27. */
  28. protected $io;
  29. /**
  30. * Apply plugin modifications to Composer
  31. *
  32. * @param Composer $composer
  33. * @param IOInterface $io
  34. */
  35. public function activate(Composer $composer, IOInterface $io) {
  36. $this->composer = $composer;
  37. $this->io = $io;
  38. }
  39. public function getCapabilities() {
  40. return [
  41. CommandProvider::class => BuilderCommandProvider::class,
  42. ];
  43. }
  44. /**
  45. * {@inheritdoc}
  46. *
  47. * Available events:
  48. *
  49. * - Composer\Installer\InstallerEvents::* -> Composer\Installer\InstallerEvent
  50. * - Composer\Installer\PackageEvents::* -> Composer\Installer\PackageEvent
  51. * - Composer\Installer\PluginEvents::INIT -> Composer\EventDispatcher\Event
  52. * - Composer\Installer\PluginEvents::COMMAND -> Composer\Plugin\CommandEvent
  53. * - Composer\Installer\PluginEvents::PRE_FILE_DOWNLOAD
  54. * -> Composer\Plugin\PreFileDownloadEvent
  55. * - Composer\Script\ScriptEvents::* -> Composer\Script\Event
  56. */
  57. public static function getSubscribedEvents() {
  58. return [
  59. ScriptEvents::POST_INSTALL_CMD => 'onScriptEvent',
  60. ScriptEvents::POST_UPDATE_CMD => 'onScriptEvent',
  61. ];
  62. }
  63. public function onScriptEvent(ScriptEvent $event) {
  64. $buildCommand = new BuildSettingsCommand($event->getName());
  65. $buildCommand->run(new ArgvInput([]), new ConsoleOutput());
  66. }
  67. }