From 1f9b934a667522bf9f21743898fd30376b0ea60f Mon Sep 17 00:00:00 2001 From: jurgenhaas <juergen.haas@lakedrops.com> Date: Fri, 25 Dec 2020 19:54:13 +0100 Subject: [PATCH] docker/l3d#58 Move project settings out of composer.json --- Config.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Config.php b/Config.php index 90744c9..af4ce60 100644 --- a/Config.php +++ b/Config.php @@ -12,6 +12,11 @@ final class Config { private static $values; + /** + * @var string + */ + private $component; + /** * Config constructor. * @@ -20,6 +25,7 @@ final class Config { * @param \LakeDrops\Component\Dotenv\Dotenv $env */ public function __construct(string $component, array $default_values, Dotenv $env) { + $this->component = $component; $this->init(); $componentValues = self::$values[$component] ?? []; self::$values[$component] = $env->replaceEnvironmentVariables(NestedArray::mergeDeep($default_values, $componentValues)); @@ -38,4 +44,32 @@ final class Config { } } + /** + * @param array $values + * @param array $keys + * + * @return mixed|null + */ + private function readValueFromArray($values, $keys) { + $key = array_shift($keys); + if (!isset($values[$key])) { + return NULL; + } + if (empty($keys)) { + return $values[$key]; + } + return $this->readValueFromArray($values[$key], $keys); + + } + + /** + * @param $path + * + * @return mixed|null + */ + public function readValue($path) { + $parts = explode('/', $path); + return $this->readValueFromArray(self::$values[$this->component], $parts); + } + } -- GitLab