diff --git a/src/Command/TransformationCommand.php b/src/Command/TransformationCommand.php index cd3921e6..4d654601 100644 --- a/src/Command/TransformationCommand.php +++ b/src/Command/TransformationCommand.php @@ -74,9 +74,18 @@ public function execute(string $file, string $source, string $workpath, bool $de new OutputLogger() ); + // reading the app_context file + $transformationDir = pathinfo($file, PATHINFO_DIRNAME); + $contextFile = $transformationDir.DIRECTORY_SEPARATOR.'app_context.yaml'; + $context = (is_file($contextFile)) ? Yaml::parseFile($contextFile) : []; + $transformationFile = ArrayFunctions::array_filter_recursive(Yaml::parseFile($file), function ($value) { return $value !== NULL; }); + + // merging it with the original MAIN-step.yaml, after this point the two are merged + $transformationFile = ArrayFunctions::array_merge_recursive($context, $transformationFile); + $configuration = $configurationFactory->parseDirectivesFromConfiguration( array_replace_recursive($transformationFile, [ 'context' => [ diff --git a/src/Component/Common/Functions/ArrayFunctions.php b/src/Component/Common/Functions/ArrayFunctions.php index 1e4a4e19..54ce6484 100644 --- a/src/Component/Common/Functions/ArrayFunctions.php +++ b/src/Component/Common/Functions/ArrayFunctions.php @@ -202,6 +202,20 @@ public static function array_filter_recursive(array $array, callable $callback): }); } + public static function array_merge_recursive(array &$array1, array $array2) { + foreach ($array2 as $key => $value) { + // If the value is an array and the key exists in both arrays + if (is_array($value) && isset($array1[$key]) && is_array($array1[$key])) { + self::array_merge_recursive($array1[$key], $value); + } else { + // Overwrite the value in the first array + $array1[$key] = $value; + } + } + + return $array1; + } + public static function fill_with_empty(array $array): array { return array_fill_keys($array, null);