Forráskód Böngészése

Implement Composer plugin features.

Frederic G. MARAND 6 éve
szülő
commit
3c5933efbe
3 módosított fájl, 135 hozzáadás és 0 törlés
  1. 1 0
      .gitignore
  2. 24 0
      composer.json
  3. 110 0
      src/Builder.php

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+/vendor/

+ 24 - 0
composer.json

@@ -0,0 +1,24 @@
+{
+  "authors": [
+    {
+      "name": "Frederic G. MARAND",
+      "email": "fgm@osinet.fr"
+    }
+  ],
+  "autoload": {
+    "psr-4": {
+      "Fgm\\Drupal\\Composer\\": "src/"
+    }
+  },
+  "description": "A Composer plugin to help build Drupal sites",
+  "extra": {
+    "class": "Fgm\\Drupal\\Composer\\Builder"
+  },
+  "license": "GPL-2.0+",
+  "minimum-stability": "dev",
+  "name": "fgm/drupal_composer__builder",
+  "require": {
+    "composer-plugin-api": "^1.1"
+  },
+  "type": "composer-plugin"
+}

+ 110 - 0
src/Builder.php

@@ -0,0 +1,110 @@
+<?php
+
+namespace Fgm\Drupal\Composer;
+
+use Composer\Composer;
+use Composer\EventDispatcher\Event;
+use Composer\EventDispatcher\EventSubscriberInterface;
+use Composer\Installer\InstallerEvents;
+use Composer\Installer\PackageEvents;
+use Composer\IO\IOInterface;
+use Composer\Plugin\Capability\CommandProvider;
+use Composer\Plugin\Capable;
+use Composer\Plugin\PluginEvents;
+use Composer\Plugin\PluginInterface;
+use Composer\Script\ScriptEvents;
+use Doctrine\Common\Util\Debug;
+
+class Builder implements Capable, EventSubscriberInterface, PluginInterface {
+
+  /**
+   * @var IOInterface
+   */
+  protected $io;
+
+  /**
+   * Apply plugin modifications to Composer
+   *
+   * @param Composer $composer
+   * @param IOInterface $io
+   */
+  public function activate(Composer $composer, IOInterface $io) {
+    Debug::dump($composer);
+    Debug::dump($io);
+    $this->io = $io;
+  }
+
+  public function getCapabilities() {
+    return [
+      CommandProvider::class => Builder::class,
+    ];
+  }
+
+  /**
+   * For CommandProvider::class.
+   */
+  public function getCommands() {
+    echo __METHOD__ . "\n";
+    return [];
+  }
+
+  /**
+   * Returns an array of event names this subscriber wants to listen to.
+   *
+   * The array keys are event names and the value can be:
+   *
+   * * The method name to call (priority defaults to 0)
+   * * An array composed of the method name to call and the priority
+   * * An array of arrays composed of the method names to call and respective
+   *   priorities, or 0 if unset
+   *
+   * For instance:
+   *
+   * * array('eventName' => 'methodName')
+   * * array('eventName' => array('methodName', $priority))
+   * * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
+   *
+   * @return array The event names to listen to
+   */
+  public static function getSubscribedEvents() {
+    return [
+      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',
+
+      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',
+    ];
+  }
+
+  public function onEvent(Event $event) {
+    $this->io->write(Debug::dump($event, 2, false, false));
+  }
+
+}