Browse Source

Reduce noise

Frederic G. MARAND 6 years ago
parent
commit
8ae1274982
2 changed files with 78 additions and 34 deletions
  1. 34 0
      src/BuildSettingsCommand.php
  2. 44 34
      src/Builder.php

+ 34 - 0
src/BuildSettingsCommand.php

@@ -0,0 +1,34 @@
+<?php
+
+namespace Fgm\Drupal\Composer;
+
+use Composer\Command\BaseCommand;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class BuildSettingsCommand extends BaseCommand {
+
+  public function __construct(string $name = NULL) {
+    parent::__construct($name);
+    echo "Constructing " . __CLASS__ . "\n";
+  }
+
+  public function configure() {
+    parent::configure();
+    $this
+      ->setName('build-settings')
+      ->setDescription('Build the settings.local.php file from the per-environment parameters and the settings template.')
+      ->setDefinition([])
+      ->setHelp(<<<EOT
+The build-settings command combines shared and per-environment parameters and passes them to the settings.local.php.twig template to build the settings/(build|run).settings.local.php files.
+
+EOT
+      )
+    ;
+  }
+
+  public function execute(InputInterface $input, OutputInterface $output) {
+    $output->write("BuildSettingsCommand Executed", true);
+  }
+
+}

+ 44 - 34
src/Builder.php

@@ -6,16 +6,17 @@ use Composer\Composer;
 use Composer\EventDispatcher\Event;
 use Composer\EventDispatcher\EventSubscriberInterface;
 use Composer\Installer\InstallerEvents;
+use Composer\Installer\PackageEvent;
 use Composer\Installer\PackageEvents;
 use Composer\IO\IOInterface;
+use Composer\Plugin\Capability\Capability;
 use Composer\Plugin\Capability\CommandProvider;
 use Composer\Plugin\Capable;
-use Composer\Plugin\PluginEvents;
 use Composer\Plugin\PluginInterface;
+use Composer\Script\Event as ScriptEvent;
 use Composer\Script\ScriptEvents;
-use Doctrine\Common\Util\Debug;
 
-class Builder implements Capable, EventSubscriberInterface, PluginInterface {
+class Builder implements Capable, Capability, CommandProvider, EventSubscriberInterface, PluginInterface {
 
   /**
    * @var IOInterface
@@ -29,8 +30,6 @@ class Builder implements Capable, EventSubscriberInterface, PluginInterface {
    * @param IOInterface $io
    */
   public function activate(Composer $composer, IOInterface $io) {
-    Debug::dump($composer);
-    Debug::dump($io);
     $this->io = $io;
   }
 
@@ -45,7 +44,9 @@ class Builder implements Capable, EventSubscriberInterface, PluginInterface {
    */
   public function getCommands() {
     echo __METHOD__ . "\n";
-    return [];
+    return [
+      new BuildSettingsCommand(),
+    ];
   }
 
   /**
@@ -71,40 +72,49 @@ class Builder implements Capable, EventSubscriberInterface, PluginInterface {
       InstallerEvents::POST_DEPENDENCIES_SOLVING => 'onEvent',
       InstallerEvents::PRE_DEPENDENCIES_SOLVING => 'onEvent',
 
-      PackageEvents::POST_PACKAGE_INSTALL => 'onEvent',
-      PackageEvents::POST_PACKAGE_UNINSTALL => 'onEvent',
-      PackageEvents::POST_PACKAGE_UPDATE => 'onEvent',
-      PackageEvents::PRE_PACKAGE_INSTALL => 'onEvent',
-      PackageEvents::PRE_PACKAGE_UNINSTALL => 'onEvent',
-      PackageEvents::PRE_PACKAGE_UPDATE => 'onEvent',
+      PackageEvents::POST_PACKAGE_INSTALL => 'onPackageEvent',
+      PackageEvents::POST_PACKAGE_UNINSTALL => 'onPackageEvent',
+      PackageEvents::POST_PACKAGE_UPDATE => 'onPackageEvent',
+      PackageEvents::PRE_PACKAGE_INSTALL => 'onPackageEvent',
+      PackageEvents::PRE_PACKAGE_UNINSTALL => 'onPackageEvent',
+      PackageEvents::PRE_PACKAGE_UPDATE => 'onPackageEvent',
 
-      PluginEvents::COMMAND => 'onEvent',
-      PluginEvents::INIT => 'onEvent',
-      PluginEvents::PRE_FILE_DOWNLOAD => 'onEvent',
+//      PluginEvents::COMMAND => 'onEvent',
+//      PluginEvents::INIT => 'onEvent',
+//      PluginEvents::PRE_FILE_DOWNLOAD => 'onEvent',
 
-      ScriptEvents::POST_ARCHIVE_CMD => 'onEvent',
-      ScriptEvents::POST_AUTOLOAD_DUMP => 'onEvent',
-      ScriptEvents::POST_CREATE_PROJECT_CMD => 'onEvent',
-      ScriptEvents::POST_INSTALL_CMD => 'onEvent',
-      ScriptEvents::POST_PACKAGE_INSTALL => 'onEvent',
-      ScriptEvents::POST_PACKAGE_UNINSTALL => 'onEvent',
-      ScriptEvents::POST_PACKAGE_UPDATE => 'onEvent',
-      ScriptEvents::POST_ROOT_PACKAGE_INSTALL => 'onEvent',
-      ScriptEvents::POST_STATUS_CMD => 'onEvent',
-      ScriptEvents::POST_UPDATE_CMD => 'onEvent',
-      ScriptEvents::PRE_ARCHIVE_CMD => 'onEvent',
-      ScriptEvents::PRE_AUTOLOAD_DUMP => 'onEvent',
-      ScriptEvents::PRE_INSTALL_CMD => 'onEvent',
-      ScriptEvents::PRE_PACKAGE_INSTALL => 'onEvent',
-      ScriptEvents::PRE_PACKAGE_UNINSTALL => 'onEvent',
-      ScriptEvents::PRE_PACKAGE_UPDATE => 'onEvent',
-      ScriptEvents::PRE_STATUS_CMD => 'onEvent',
-      ScriptEvents::PRE_UPDATE_CMD => 'onEvent',
+//      ScriptEvents::POST_ARCHIVE_CMD => 'onScriptEvent',
+//      ScriptEvents::POST_AUTOLOAD_DUMP => 'onScriptEvent',
+//      ScriptEvents::POST_CREATE_PROJECT_CMD => 'onScriptEvent',
+      ScriptEvents::POST_INSTALL_CMD => 'onScriptEvent',
+//      ScriptEvents::POST_ROOT_PACKAGE_INSTALL => 'onScriptEvent',
+//      ScriptEvents::POST_STATUS_CMD => 'onScriptEvent',
+      ScriptEvents::POST_UPDATE_CMD => 'onScriptEvent',
+//      ScriptEvents::PRE_ARCHIVE_CMD => 'onScriptEvent',
+//      ScriptEvents::PRE_AUTOLOAD_DUMP => 'onScriptEvent',
+//      ScriptEvents::PRE_INSTALL_CMD => 'onScriptEvent',
+//      ScriptEvents::PRE_STATUS_CMD => 'onScriptEvent',
+//      ScriptEvents::PRE_UPDATE_CMD => 'onScriptEvent',
     ];
   }
 
   public function onEvent(Event $event) {
-    $this->io->write(Debug::dump($event, 2, false, false));
+    $this->io->write($event->getName());
   }
 
+  public function onPackageEvent(PackageEvent $event) {
+    $this->io->write([
+      $event->getName(),
+      $event->getOperation()->getJobType() . ' - ' . $event->getOperation()->getReason(),
+      json_encode($event->getArguments()),
+      json_encode($event->getInstalledRepo()->getRepositories()),
+    ]);
+  }
+
+  public function onScriptEvent(ScriptEvent $event) {
+    $this->io->write([
+      $event->getName(),
+      json_encode($event->getArguments()),
+    ]);
+  }
 }