X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fconsolidation%2Fconfig%2Fsrc%2FUtil%2FArrayUtil.php;fp=vendor%2Fconsolidation%2Fconfig%2Fsrc%2FUtil%2FArrayUtil.php;h=d5748a7a2a88ca5dd03b663af93315f9cdc464fe;hp=a23f854e8692039e5ab988c004d39913afd86054;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/vendor/consolidation/config/src/Util/ArrayUtil.php b/vendor/consolidation/config/src/Util/ArrayUtil.php index a23f854e8..d5748a7a2 100644 --- a/vendor/consolidation/config/src/Util/ArrayUtil.php +++ b/vendor/consolidation/config/src/Util/ArrayUtil.php @@ -40,6 +40,53 @@ class ArrayUtil return $value; } + + /** + * Merges arrays recursively while preserving. + * + * @param array $array1 + * @param array $array2 + * + * @return array + * + * @see http://php.net/manual/en/function.array-merge-recursive.php#92195 + * @see https://github.com/grasmash/bolt/blob/robo-rebase/src/Robo/Common/ArrayManipulator.php#L22 + */ + public static function mergeRecursiveSelect( + array &$array1, + array &$array2, + array $selectionList, + $keyPrefix = '' + ) { + $merged = $array1; + foreach ($array2 as $key => &$value) { + $merged[$key] = self::mergeRecursiveSelectValue($merged, $key, $value, $selectionList, $keyPrefix); + } + return $merged; + } + + /** + * Process the value in an mergeRecursiveDistinct - make a recursive + * call if needed. + */ + protected static function mergeRecursiveSelectValue(&$merged, $key, $value, $selectionList, $keyPrefix) + { + if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) { + if (self::selectMerge($keyPrefix, $key, $selectionList)) { + return array_merge_recursive($merged[$key], $value); + } else { + return self::mergeRecursiveSelect($merged[$key], $value, $selectionList, "${keyPrefix}${key}."); + } + } + return $value; + } + + protected static function selectMerge($keyPrefix, $key, $selectionList) + { + return in_array("${keyPrefix}${key}", $selectionList); + } + + /** * Fills all of the leaf-node values of a nested array with the * provided replacement value.