diff --git a/BaseHandler.php b/BaseHandler.php index 504c388eb6d553e250f3b6dc4d79e553bc177c55..89cce825dc09d6f5acf7d89acd3c3176ae2e8359 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 c153c6fb54fdd2bd466c23008a84021b30b3334e..90744c997d2b9b02c08b768c07f456c19daf136c 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 4ad938d1218e72c8bbedc00f54ad5153f566d139..a27d728e54f9d7ce96a522c773b2843db57be8b9 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": {