From e06d1abc06b29483e1196059efd54de876d2bc95 Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen.haas@lakedrops.com>
Date: Fri, 25 Dec 2020 19:40:16 +0100
Subject: [PATCH] docker/l3d#58 Move project settings out of composer.json

---
 BaseHandler.php | 15 ++++++++++++++-
 Config.php      |  6 ++++--
 composer.json   |  1 +
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/BaseHandler.php b/BaseHandler.php
index 504c388..89cce82 100644
--- a/BaseHandler.php
+++ b/BaseHandler.php
@@ -6,6 +6,7 @@ use Composer\Composer;
 use Composer\IO\IOInterface;
 use Composer\Package\PackageInterface;
 use Composer\Script\Event;
+use LakeDrops\Component\Dotenv\Dotenv;
 use Symfony\Component\Console\Input\InputInterface;
 
 /**
@@ -55,6 +56,11 @@ abstract class BaseHandler implements BaseHandlerInterface {
    */
   protected $drupalCorePackage;
 
+  /**
+   * @var \LakeDrops\Component\Dotenv\Dotenv
+   */
+  protected $env;
+
   /**
    * Handler constructor.
    *
@@ -66,7 +72,9 @@ abstract class BaseHandler implements BaseHandlerInterface {
   public function __construct(Composer $composer, IOInterface $io) {
     $this->composer = $composer;
     $this->io = $io;
-    $this->config = new Config($this->configId(), $this->configDefault());
+    $this->env = new Dotenv('docker4drupal', $this->io);
+    $this->config = new Config($this->configId(), $this->configDefault(), $this->env);
+    $this->postInit();
   }
 
   /**
@@ -76,6 +84,11 @@ abstract class BaseHandler implements BaseHandlerInterface {
     return [];
   }
 
+  /**
+   * May be overwritten by implementing classes.
+   */
+  protected function postInit(): void {}
+
   /**
    * {@inheritdoc}
    */
diff --git a/Config.php b/Config.php
index c153c6f..90744c9 100644
--- a/Config.php
+++ b/Config.php
@@ -2,6 +2,7 @@
 
 namespace LakeDrops\Component\Composer;
 
+use LakeDrops\Component\Dotenv\Dotenv;
 use Symfony\Component\Yaml\Yaml;
 
 /**
@@ -16,11 +17,12 @@ final class Config {
    *
    * @param string $component
    * @param array $default_values
+   * @param \LakeDrops\Component\Dotenv\Dotenv $env
    */
-  public function __construct(string $component, array $default_values) {
+  public function __construct(string $component, array $default_values, Dotenv $env) {
     $this->init();
     $componentValues = self::$values[$component] ?? [];
-    self::$values[$component] = NestedArray::mergeDeep($default_values, $componentValues);
+    self::$values[$component] = $env->replaceEnvironmentVariables(NestedArray::mergeDeep($default_values, $componentValues));
   }
 
   /**
diff --git a/composer.json b/composer.json
index 4ad938d..a27d728 100644
--- a/composer.json
+++ b/composer.json
@@ -26,6 +26,7 @@
     "require": {
         "php": ">=7.2",
         "ext-json": "*",
+        "lakedrops/dotenv": "^1.5||dev-master",
         "symfony/yaml": "^3.4||^4.4||^5.0"
     },
     "require-dev": {
-- 
GitLab