Skip to content

Commit

Permalink
Allow to fully overwrite default config arrays (#194)
Browse files Browse the repository at this point in the history
* Fix isAttachment that did not properly take in consideration dispositions options

* Query::chunked does not loop over the last chunk

* Allow to fully overwrite default config arrays

Co-authored-by: Nourisson Laurent
  • Loading branch information
laurent-rizer authored Feb 3, 2022
1 parent 77c12b8 commit 684cc9e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/ClientManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ private function array_merge_recursive_distinct() {
$arrays = func_get_args();
$base = array_shift($arrays);

// From https://stackoverflow.com/a/173479
$isAssoc = function(array $arr) {
if (array() === $arr) return false;
return array_keys($arr) !== range(0, count($arr) - 1);
};

if(!is_array($base)) $base = empty($base) ? array() : array($base);

foreach($arrays as $append) {
Expand All @@ -245,7 +251,19 @@ private function array_merge_recursive_distinct() {
continue;
}

if(is_array($value) or is_array($base[$key])) {
if(
(
is_array($value)
&& $isAssoc($value)
)
|| (
is_array($base[$key])
&& $isAssoc($base[$key])
)
) {
// If the arrays are not associates we don't want to array_merge_recursive_distinct
// else merging $baseConfig['dispositions'] = ['attachment', 'inline'] with $customConfig['dispositions'] = ['attachment']
// results in $resultConfig['dispositions'] = ['attachment', 'inline']
$base[$key] = $this->array_merge_recursive_distinct($base[$key], $append[$key]);
} else if(is_numeric($key)) {
if(!in_array($value, $base)) $base[] = $value;
Expand Down

0 comments on commit 684cc9e

Please sign in to comment.