Skip to content

Commit

Permalink
added: app_context.yaml file
Browse files Browse the repository at this point in the history
  • Loading branch information
Thijzer committed Nov 28, 2024
1 parent 31da7c7 commit e927c2f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Command/TransformationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
14 changes: 14 additions & 0 deletions src/Component/Common/Functions/ArrayFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e927c2f

Please sign in to comment.