1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- declare(strict_types = 1);
- namespace Fgm\Drupal\Composer;
- use Composer\Composer;
- use Composer\EventDispatcher\EventSubscriberInterface;
- use Composer\IO\IOInterface;
- use Composer\Plugin\Capability\Capability;
- use Composer\Plugin\Capability\CommandProvider;
- use Composer\Plugin\Capable;
- use Composer\Plugin\PluginInterface;
- use Composer\Script\Event as ScriptEvent;
- use Composer\Script\ScriptEvents;
- class Builder implements Capable, Capability, EventSubscriberInterface, PluginInterface
- {
- const NAME = "composer_builder";
- /**
- * @var \Composer\Composer
- */
- protected $composer;
- /**
- * @var \Composer\IO\IOInterface
- */
- protected $io;
- /**
- * {@inheritdoc}
- *
- * Available events:
- *
- * - Composer\Installer\InstallerEvents::* ->
- * Composer\Installer\InstallerEvent
- * - Composer\Installer\PackageEvents::* -> Composer\Installer\PackageEvent
- * - Composer\Installer\PluginEvents::INIT -> Composer\EventDispatcher\Event
- * - Composer\Installer\PluginEvents::COMMAND -> Composer\Plugin\CommandEvent
- * - Composer\Installer\PluginEvents::PRE_FILE_DOWNLOAD
- * -> Composer\Plugin\PreFileDownloadEvent
- * - Composer\Script\ScriptEvents::* -> Composer\Script\Event
- */
- public static function getSubscribedEvents()
- {
- return [
- ScriptEvents::POST_INSTALL_CMD => 'onScriptEvent',
- ScriptEvents::POST_UPDATE_CMD => 'onScriptEvent',
- ];
- }
- /**
- * Apply plugin modifications to Composer
- *
- * @param Composer $composer
- * @param IOInterface $io
- */
- public function activate(Composer $composer, IOInterface $io)
- {
- $this->composer = $composer;
- $this->io = $io;
- }
- /**
- * {@inheritDoc}
- */
- public function getCapabilities()
- {
- return [
- CommandProvider::class => BuilderCommandProvider::class,
- ];
- }
- /**
- * Event callback: run build:settings on post-install|update only.
- *
- * @param \Composer\Script\Event $event
- *
- * @throws \Exception
- */
- public function onScriptEvent(ScriptEvent $event)
- {
- if (in_array($event->getName(), [
- ScriptEvents::POST_INSTALL_CMD,
- ScriptEvents::POST_UPDATE_CMD,
- ]
- )
- ) {
- // FIXME add behavior where, without an argument, the command will build all templates.
- // $buildCommand = new BuildSettingsCommand($event->getName());
- // $buildCommand->run(new ArgvInput([]), new ConsoleOutput());
- }
- }
- }
|