From 2073a5a4156aa8f2849f2e81e2b743f338ed3f45 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 5 Oct 2024 05:27:18 +0200 Subject: [PATCH] removed support for key PreventMerging (BC break) --- src/Schema/Elements/AnyOf.php | 5 ----- src/Schema/Elements/Structure.php | 8 -------- src/Schema/Elements/Type.php | 19 ++--------------- tests/Schema/Expect.array.phpt | 34 ------------------------------- 4 files changed, 2 insertions(+), 64 deletions(-) diff --git a/src/Schema/Elements/AnyOf.php b/src/Schema/Elements/AnyOf.php index 6c9d0ce..71a68f3 100644 --- a/src/Schema/Elements/AnyOf.php +++ b/src/Schema/Elements/AnyOf.php @@ -64,11 +64,6 @@ public function normalize(mixed $value, Context $context): mixed public function merge(mixed $value, mixed $base): mixed { - if (is_array($value) && isset($value[Helpers::PreventMerging])) { - unset($value[Helpers::PreventMerging]); - return $value; - } - return Helpers::merge($value, $base); } diff --git a/src/Schema/Elements/Structure.php b/src/Schema/Elements/Structure.php index 66e501a..8b83b71 100644 --- a/src/Schema/Elements/Structure.php +++ b/src/Schema/Elements/Structure.php @@ -94,10 +94,6 @@ public function getShape(): array public function normalize(mixed $value, Context $context): mixed { - if ($prevent = (is_array($value) && isset($value[Helpers::PreventMerging]))) { - unset($value[Helpers::PreventMerging]); - } - $value = $this->doNormalize($value, $context); if (is_object($value)) { $value = (array) $value; @@ -112,10 +108,6 @@ public function normalize(mixed $value, Context $context): mixed array_pop($context->path); } } - - if ($prevent) { - $value[Helpers::PreventMerging] = true; - } } return $value; diff --git a/src/Schema/Elements/Type.php b/src/Schema/Elements/Type.php index 7b53385..aa657d0 100644 --- a/src/Schema/Elements/Type.php +++ b/src/Schema/Elements/Type.php @@ -112,10 +112,6 @@ public function pattern(?string $pattern): self public function normalize(mixed $value, Context $context): mixed { - if ($prevent = (is_array($value) && isset($value[Helpers::PreventMerging]))) { - unset($value[Helpers::PreventMerging]); - } - $value = $this->doNormalize($value, $context); if (is_array($value) && $this->itemsValue) { $res = []; @@ -133,18 +129,13 @@ public function normalize(mixed $value, Context $context): mixed $value = $res; } - if ($prevent && is_array($value)) { - $value[Helpers::PreventMerging] = true; - } - return $value; } public function merge(mixed $value, mixed $base): mixed { - if ($this->mergeMode === MergeMode::Replace || (is_array($value) && isset($value[Helpers::PreventMerging]))) { - unset($value[Helpers::PreventMerging]); + if ($this->mergeMode === MergeMode::Replace) { return $value; } @@ -170,12 +161,6 @@ public function merge(mixed $value, mixed $base): mixed public function complete(mixed $value, Context $context): mixed { - $merge = $this->merge; - if (is_array($value) && isset($value[Helpers::PreventMerging])) { - unset($value[Helpers::PreventMerging]); - $merge = false; - } - if ($value === null && is_array($this->default)) { $value = []; // is unable to distinguish null from array in NEON } @@ -187,7 +172,7 @@ public function complete(mixed $value, Context $context): mixed $isOk() && Helpers::validateRange($value, $this->range, $context, $this->type); $isOk() && $value !== null && $this->pattern !== null && Helpers::validatePattern($value, $this->pattern, $context); $isOk() && is_array($value) && $this->validateItems($value, $context); - $isOk() && $merge && $value = Helpers::merge($value, $this->default); + $isOk() && $this->merge && $value = Helpers::merge($value, $this->default); $isOk() && $value = $this->doTransform($value, $context); if (!$isOk()) { return null; diff --git a/tests/Schema/Expect.array.phpt b/tests/Schema/Expect.array.phpt index 7bd2679..26cee0a 100644 --- a/tests/Schema/Expect.array.phpt +++ b/tests/Schema/Expect.array.phpt @@ -3,7 +3,6 @@ declare(strict_types=1); use Nette\Schema\Expect; -use Nette\Schema\Helpers; use Nette\Schema\MergeMode; use Nette\Schema\Processor; use Tester\Assert; @@ -96,39 +95,6 @@ test('merging default value', function () { 'arr' => ['newitem'], ]), ); - - Assert::same( - [ - 'key1' => 'newval', - 'key3' => 'newval', - 'newval3', - 'arr' => ['newitem'], - ], - (new Processor)->process($schema, [ - Helpers::PreventMerging => true, - 'key1' => 'newval', - 'key3' => 'newval', - 'newval3', - 'arr' => ['newitem'], - ]), - ); - - Assert::same( - [ - 'key1' => 'newval', - 'key2' => 'val2', - 'val3', - 'arr' => ['newitem'], - 'key3' => 'newval', - 'newval3', - ], - (new Processor)->process($schema, [ - 'key1' => 'newval', - 'key3' => 'newval', - 'newval3', - 'arr' => [Helpers::PreventMerging => true, 'newitem'], - ]), - ); });