Skip to content

Commit 99c09bc

Browse files
authored
Fix merge
1 parent e5e611f commit 99c09bc

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/File.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,14 +596,38 @@ public function withoutMetadataKey(string $key): FileInterface
596596
public function withVariants(array $variants, bool $merge = true): FileInterface
597597
{
598598
$that = clone $this;
599-
$that->variants = array_merge_recursive(
599+
$that->variants = $this->arrayMergeDeep(
600600
$merge ? $that->variants : [],
601601
$variants,
602602
);
603603

604604
return $that;
605605
}
606606

607+
/**
608+
* Sets many variants at once
609+
*
610+
* @param array $array1
611+
* @param array $array2
612+
*
613+
* @return array
614+
*/
615+
protected function arrayMergeDeep(array $array1, array $array2): array {
616+
foreach ($array2 as $key => $value) {
617+
if (
618+
isset($array1[$key]) &&
619+
is_array($array1[$key]) &&
620+
is_array($value)
621+
) {
622+
$array1[$key] = $this->arrayMergeDeep($array1[$key], $value);
623+
} else {
624+
$array1[$key] = $value;
625+
}
626+
}
627+
628+
return $array1;
629+
}
630+
607631
/**
608632
* @inheritDoc
609633
*/

0 commit comments

Comments
 (0)