Skip to content

Commit

Permalink
tweak(Tinebase/Config): deep merge conf.d config files
Browse files Browse the repository at this point in the history
  • Loading branch information
byteplow committed Jan 8, 2025
1 parent eb7dc2f commit 9cffa62
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions tine20/Tinebase/Config/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ protected function _doCreateCachedConfig($cachedConfigData)
$cachedConfigData['ttlstamp'] < time() ||
(defined('TINE20_BUILDTYPE') && (TINE20_BUILDTYPE === 'DEVELOPMENT' || TINE20_BUILDTYPE === 'DEBUG'));
}

/**
* composes config files from conf.d and saves array to tmp file
*/
Expand Down Expand Up @@ -542,9 +542,7 @@ protected function _createCachedConfig()
}

if (false !== $tmpArray && is_array($tmpArray)) {
foreach ($tmpArray as $key => $value) {
self::$_configFileData[$key] = $value;
}
self::$_configFileData = self::_array_merge_recursive_distinct(self::$_configFileData, $tmpArray);
}
}

Expand Down Expand Up @@ -663,6 +661,26 @@ protected function _getConfdFileDataJson($filename)
return false;
}

/**
* Merges arrays recursively. Overwrites non-array keys, unlike array_merge_recursive. Array2 takes precedence.
* @param $array1
* @param $array2
* @return array
*/
static function _array_merge_recursive_distinct(&$array1, &$array2) {
$merged = $array1;

foreach ($array2 as $key => &$value) {
if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
$merged[$key] = self::_array_merge_recursive_distinct($merged[$key], $value);
} else {
$merged[$key] = $value;
}
}

return $merged;
}

/**
* returns data from application specific config.inc.php file
*
Expand Down

0 comments on commit 9cffa62

Please sign in to comment.