From adb13ea44783248c27e2d8351375734dd9188cca Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 5 Oct 2024 04:19:27 +0200 Subject: [PATCH] Type::merge() merges arrays only according to the schema (BC break) --- src/Schema/Elements/Type.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Schema/Elements/Type.php b/src/Schema/Elements/Type.php index c752e0c..7b53385 100644 --- a/src/Schema/Elements/Type.php +++ b/src/Schema/Elements/Type.php @@ -28,7 +28,7 @@ final class Type implements Schema private array $range = [null, null]; private ?string $pattern = null; private bool $merge = false; - private ?MergeMode $mergeMode = null; + private MergeMode $mergeMode = MergeMode::AppendKeys; public function __construct(string $type) @@ -148,7 +148,7 @@ public function merge(mixed $value, mixed $base): mixed return $value; } - if (is_array($value) && is_array($base) && ($this->itemsValue || $this->mergeMode)) { + if (is_array($value) && is_array($base)) { $index = $this->mergeMode === MergeMode::OverwriteKeys ? null : 0; foreach ($value as $key => $val) { if ($key === $index) { @@ -164,7 +164,7 @@ public function merge(mixed $value, mixed $base): mixed return $base; } - return Helpers::merge($value, $base); + return $value === null && is_array($base) ? $base : $value; }