From e6fb9544f9b3be64b044d7615833e7957898fd89 Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Thu, 1 Nov 2018 10:28:24 +0100
Subject: [PATCH] Refactor namespace to extend LakeDrops Composer Components

---
 composer.json   |  2 +-
 src/Handler.php | 79 ++++---------------------------------------------
 src/Plugin.php  | 22 +++++---------
 3 files changed, 15 insertions(+), 88 deletions(-)

diff --git a/composer.json b/composer.json
index 4da83c1..5f21f31 100644
--- a/composer.json
+++ b/composer.json
@@ -26,7 +26,7 @@
     "require": {
         "php": ">=5.6",
         "composer-plugin-api": "^1.0.0",
-        "lakedrops/composer-scripts": "^1.0.0",
+        "lakedrops/composer-scripts": "^1.1.0",
         "lakedrops/docker-traefik": "^1.1.0",
         "lakedrops/dotenv": "^1.0.0",
         "twig/twig": "^1.23.1"
diff --git a/src/Handler.php b/src/Handler.php
index d6c8fd6..dcb870b 100644
--- a/src/Handler.php
+++ b/src/Handler.php
@@ -2,9 +2,8 @@
 
 namespace LakeDrops\Docker4Drupal;
 
-use Composer\Composer;
-use Composer\IO\IOInterface;
 use Composer\Script\Event;
+use LakeDrops\Component\Composer\BaseHandler;
 use LakeDrops\Component\Dotenv\Dotenv;
 use LakeDrops\DockerTraefik\Traefik;
 use Symfony\Component\Filesystem\Filesystem;
@@ -15,67 +14,7 @@ use Symfony\Component\Yaml\Yaml;
  *
  * @package LakeDrops\Docker4Drupal
  */
-class Handler {
-
-  /**
-   * The composer object of this session.
-   *
-   * @var \Composer\Composer
-   */
-  protected $composer;
-
-  /**
-   * The input-output object of the composer session.
-   *
-   * @var \Composer\IO\IOInterface
-   */
-  protected $io;
-
-  /**
-   * The Drupal core package.
-   *
-   * @var \Composer\Package\PackageInterface
-   */
-  protected $drupalCorePackage;
-
-  /**
-   * Handler constructor.
-   *
-   * @param \Composer\Composer $composer
-   *   The composer object of this session.
-   * @param \Composer\IO\IOInterface $io
-   *   The input-output object of the composer session.
-   */
-  public function __construct(Composer $composer, IOInterface $io) {
-    $this->composer = $composer;
-    $this->io = $io;
-  }
-
-  /**
-   * Look up the Drupal core package object.
-   *
-   * @return \Composer\Package\PackageInterface
-   *   The Drupal core package.
-   */
-  protected function getDrupalCorePackage() {
-    if (!isset($this->drupalCorePackage)) {
-      $this->drupalCorePackage = $this->getPackage('drupal/core');
-    }
-    return $this->drupalCorePackage;
-  }
-
-  /**
-   * Retrieve a package from the current composer process.
-   *
-   * @param string $name
-   *   Name of the package to get from the current composer installation.
-   *
-   * @return \Composer\Package\PackageInterface
-   *   The package.
-   */
-  protected function getPackage($name) {
-    return $this->composer->getRepositoryManager()->getLocalRepository()->findPackage($name, '*');
-  }
+class Handler extends BaseHandler {
 
   /**
    * Configure Drupal Project for Docker.
@@ -84,6 +23,10 @@ class Handler {
    *   The event that triggered the call of this function.
    * @param bool $overwrite
    *   Whether to overwrite existing config files.
+   *
+   * @throws \Twig_Error_Loader
+   * @throws \Twig_Error_Runtime
+   * @throws \Twig_Error_Syntax
    */
   public function configureProject(Event $event, $overwrite = FALSE) {
 
@@ -335,16 +278,6 @@ class Handler {
     return $env->replaceEnvironmentVariables($options);
   }
 
-  /**
-   * Wrapper for git command in the root directory.
-   *
-   * @param string $command
-   *   Git command name, arguments and/or options.
-   */
-  protected function git($command) {
-    passthru(escapeshellcmd('git -c "user.email=d8-project@lakedrops.com" ' . $command));
-  }
-
   /**
    * Determine local ipv4 address.
    *
diff --git a/src/Plugin.php b/src/Plugin.php
index af56d8f..2d6363e 100644
--- a/src/Plugin.php
+++ b/src/Plugin.php
@@ -2,30 +2,20 @@
 
 namespace LakeDrops\Docker4Drupal;
 
-use Composer\Composer;
-use Composer\EventDispatcher\EventSubscriberInterface;
-use Composer\IO\IOInterface;
-use Composer\Plugin\PluginInterface;
 use Composer\Script\Event;
 use Composer\Script\ScriptEvents;
+use LakeDrops\Component\Composer\BasePlugin;
 
 /**
  * Composer plugin for handling docker4drupal setup.
  */
-class Plugin implements PluginInterface, EventSubscriberInterface {
-
-  /**
-   * The handler object to configure the project for docker.
-   *
-   * @var \LakeDrops\Docker4Drupal\Handler
-   */
-  protected $handler;
+class Plugin extends BasePlugin {
 
   /**
    * {@inheritdoc}
    */
-  public function activate(Composer $composer, IOInterface $io) {
-    $this->handler = new Handler($composer, $io);
+  public function getHandlerClass() {
+    return Handler::class;
   }
 
   /**
@@ -54,6 +44,10 @@ class Plugin implements PluginInterface, EventSubscriberInterface {
    *
    * @param \Composer\Script\Event $event
    *   The event that triggered the call of this function.
+   *
+   * @throws \Twig_Error_Loader
+   * @throws \Twig_Error_Runtime
+   * @throws \Twig_Error_Syntax
    */
   public static function config(Event $event) {
     $handler = new Handler($event->getComposer(), $event->getIO());
-- 
GitLab