Builder.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. declare(strict_types = 1);
  3. namespace Fgm\Drupal\Composer;
  4. use Composer\Composer;
  5. use Composer\EventDispatcher\EventSubscriberInterface;
  6. use Composer\IO\IOInterface;
  7. use Composer\Plugin\Capability\Capability;
  8. use Composer\Plugin\Capability\CommandProvider;
  9. use Composer\Plugin\Capable;
  10. use Composer\Plugin\PluginInterface;
  11. use Composer\Script\Event as ScriptEvent;
  12. use Composer\Script\ScriptEvents;
  13. class Builder implements Capable, Capability, EventSubscriberInterface, PluginInterface
  14. {
  15. const NAME = "composer_builder";
  16. /**
  17. * @var \Composer\Composer
  18. */
  19. protected $composer;
  20. /**
  21. * @var \Composer\IO\IOInterface
  22. */
  23. protected $io;
  24. /**
  25. * {@inheritdoc}
  26. *
  27. * Available events:
  28. *
  29. * - Composer\Installer\InstallerEvents::* ->
  30. * Composer\Installer\InstallerEvent
  31. * - Composer\Installer\PackageEvents::* -> Composer\Installer\PackageEvent
  32. * - Composer\Installer\PluginEvents::INIT -> Composer\EventDispatcher\Event
  33. * - Composer\Installer\PluginEvents::COMMAND -> Composer\Plugin\CommandEvent
  34. * - Composer\Installer\PluginEvents::PRE_FILE_DOWNLOAD
  35. * -> Composer\Plugin\PreFileDownloadEvent
  36. * - Composer\Script\ScriptEvents::* -> Composer\Script\Event
  37. */
  38. public static function getSubscribedEvents()
  39. {
  40. return [
  41. ScriptEvents::POST_INSTALL_CMD => 'onScriptEvent',
  42. ScriptEvents::POST_UPDATE_CMD => 'onScriptEvent',
  43. ];
  44. }
  45. /**
  46. * Apply plugin modifications to Composer
  47. *
  48. * @param Composer $composer
  49. * @param IOInterface $io
  50. */
  51. public function activate(Composer $composer, IOInterface $io)
  52. {
  53. $this->composer = $composer;
  54. $this->io = $io;
  55. }
  56. /**
  57. * {@inheritDoc}
  58. */
  59. public function getCapabilities()
  60. {
  61. return [
  62. CommandProvider::class => BuilderCommandProvider::class,
  63. ];
  64. }
  65. /**
  66. * Event callback: run build:settings on post-install|update only.
  67. *
  68. * @param \Composer\Script\Event $event
  69. *
  70. * @throws \Exception
  71. */
  72. public function onScriptEvent(ScriptEvent $event)
  73. {
  74. if (in_array($event->getName(), [
  75. ScriptEvents::POST_INSTALL_CMD,
  76. ScriptEvents::POST_UPDATE_CMD,
  77. ]
  78. )
  79. ) {
  80. // FIXME add behavior where, without an argument, the command will build all templates.
  81. // $buildCommand = new BuildSettingsCommand($event->getName());
  82. // $buildCommand->run(new ArgvInput([]), new ConsoleOutput());
  83. }
  84. }
  85. }