Skip to content
Snippets Groups Projects
Commit 3224c867 authored by jurgenhaas's avatar jurgenhaas
Browse files

docker/l3d#58 Move project settings out of composer.json

parent 24db58f8
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,11 @@ final class Config { ...@@ -19,6 +19,11 @@ final class Config {
*/ */
private static $values; private static $values;
/**
* @var array
*/
private static $customValues;
/** /**
* @var string * @var string
*/ */
...@@ -56,11 +61,10 @@ final class Config { ...@@ -56,11 +61,10 @@ final class Config {
$this->env = $env; $this->env = $env;
$this->twig_loader = new Twig_Loader_Array([]); $this->twig_loader = new Twig_Loader_Array([]);
$this->twig = new Twig_Environment($this->twig_loader); $this->twig = new Twig_Environment($this->twig_loader);
$this->configFile = getcwd() . '/.project.yaml'; $this->configFile = getcwd() . '/.lakedrops.yml';
$this->init(); $this->init();
$componentValues = self::$values[$component] ?? []; $this->merge($default_values, []);
$this->merge($default_values, $componentValues);
} }
/** /**
...@@ -68,29 +72,40 @@ final class Config { ...@@ -68,29 +72,40 @@ final class Config {
*/ */
private function init(): void { private function init(): void {
if (self::$values === NULL) { if (self::$values === NULL) {
self::$values = [];
if (!file_exists($this->configFile)) { if (!file_exists($this->configFile)) {
self::$values = []; self::$customValues = [];
$this->save(); $this->save();
} }
else { else {
self::$values = Yaml::parseFile($this->configFile); self::$customValues = Yaml::parseFile($this->configFile);
} }
} }
} }
/** /**
* @param array $values1 * @param array $defaultValues
* @param array $values2 * @param array $customValues
*/ */
private function merge(array $values1, array $values2): void { private function merge(array $defaultValues, array $customValues): void {
self::$values[$this->component] = $this->env->replaceEnvironmentVariables(NestedArray::mergeDeep($values1, $values2)); $default = self::$values[$this->component] ?? [];
$custom = self::$customValues[$this->component] ?? [];
if (!empty($defaultValues)) {
$default = NestedArray::mergeDeep($default, $defaultValues);
}
if (!empty($customValues)) {
$default = NestedArray::mergeDeep($default, $customValues);
$custom = NestedArray::mergeDeep($custom, $customValues);
}
self::$values[$this->component] = $this->env->replaceEnvironmentVariables($default);
self::$customValues[$this->component] = $custom;
} }
/** /**
* Save the current settings. * Save the current settings.
*/ */
private function save(): void { private function save(): void {
file_put_contents($this->configFile, Yaml::dump(self::$values, 9, 2)); file_put_contents($this->configFile, Yaml::dump(self::$customValues, 9, 2));
} }
/** /**
...@@ -111,20 +126,23 @@ final class Config { ...@@ -111,20 +126,23 @@ final class Config {
} }
/** /**
* @param $path * @param string|array $keys
* *
* @return mixed|null * @return mixed|null
*/ */
public function readValue($path) { public function readValue($keys) {
$parts = explode('/', $path); if (is_string($keys)) {
return $this->readValueFromArray(self::$values[$this->component], $parts); $keys = [$keys];
}
return $this->readValueFromArray(self::$values[$this->component], $keys);
} }
/** /**
* @param string $key
* @param array $values * @param array $values
*/ */
public function setValue(array $values): void { public function setValue(string $key, array $values): void {
$this->merge(self::$values[$this->component], [$this->component => $values]); $this->merge([], [$this->component => [$key => $values]]);
$this->save(); $this->save();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment