Skip to content

Commit 7e37950

Browse files
committed
removed support for key PreventMerging (BC break)
1 parent d31c249 commit 7e37950

4 files changed

Lines changed: 3 additions & 65 deletions

File tree

src/Schema/Elements/AnyOf.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Nette\Schema\Context;
1212
use Nette\Schema\Helpers;
1313
use Nette\Schema\Schema;
14-
use function array_merge, array_unique, implode, is_array;
14+
use function array_merge, array_unique, implode;
1515

1616

1717
/**
@@ -76,11 +76,6 @@ public function normalize(mixed $value, Context $context): mixed
7676

7777
public function merge(mixed $value, mixed $base): mixed
7878
{
79-
if (is_array($value) && isset($value[Helpers::PreventMerging])) {
80-
unset($value[Helpers::PreventMerging]);
81-
return $value;
82-
}
83-
8479
return Helpers::merge($value, $base);
8580
}
8681

src/Schema/Elements/Structure.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ public function getShape(): array
105105

106106
public function normalize(mixed $value, Context $context): mixed
107107
{
108-
if ($prevent = (is_array($value) && isset($value[Helpers::PreventMerging]))) {
109-
unset($value[Helpers::PreventMerging]);
110-
}
111-
112108
$value = $this->doNormalize($value, $context);
113109
if (is_object($value)) {
114110
$value = (array) $value;
@@ -123,10 +119,6 @@ public function normalize(mixed $value, Context $context): mixed
123119
array_pop($context->path);
124120
}
125121
}
126-
127-
if ($prevent) {
128-
$value[Helpers::PreventMerging] = true;
129-
}
130122
}
131123

132124
return $value;

src/Schema/Elements/Type.php

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,6 @@ public function pattern(?string $pattern): self
123123

124124
public function normalize(mixed $value, Context $context): mixed
125125
{
126-
if ($prevent = (is_array($value) && isset($value[Helpers::PreventMerging]))) {
127-
unset($value[Helpers::PreventMerging]);
128-
}
129-
130126
$value = $this->doNormalize($value, $context);
131127
if (is_array($value) && $this->itemsValue) {
132128
$res = [];
@@ -144,18 +140,13 @@ public function normalize(mixed $value, Context $context): mixed
144140
$value = $res;
145141
}
146142

147-
if ($prevent && is_array($value)) {
148-
$value[Helpers::PreventMerging] = true;
149-
}
150-
151143
return $value;
152144
}
153145

154146

155147
public function merge(mixed $value, mixed $base): mixed
156148
{
157-
if ($this->mergeMode === MergeMode::Replace || (is_array($value) && isset($value[Helpers::PreventMerging]))) {
158-
unset($value[Helpers::PreventMerging]);
149+
if ($this->mergeMode === MergeMode::Replace) {
159150
return $value;
160151
}
161152

@@ -181,12 +172,6 @@ public function merge(mixed $value, mixed $base): mixed
181172

182173
public function complete(mixed $value, Context $context): mixed
183174
{
184-
$merge = $this->merge;
185-
if (is_array($value) && isset($value[Helpers::PreventMerging])) {
186-
unset($value[Helpers::PreventMerging]);
187-
$merge = false;
188-
}
189-
190175
if ($value === null && is_array($this->default)) {
191176
$value = []; // is unable to distinguish null from array in NEON
192177
}
@@ -198,7 +183,7 @@ public function complete(mixed $value, Context $context): mixed
198183
$isOk() && Helpers::validateRange($value, $this->range, $context, $this->type);
199184
$isOk() && $value !== null && $this->pattern !== null && Helpers::validatePattern($value, $this->pattern, $context);
200185
$isOk() && is_array($value) && $this->validateItems($value, $context);
201-
$isOk() && $merge && $value = Helpers::merge($value, $this->default);
186+
$isOk() && $this->merge && $value = Helpers::merge($value, $this->default);
202187
$isOk() && $value = $this->doTransform($value, $context);
203188
if (!$isOk()) {
204189
return null;

tests/Schema/Expect.array.phpt

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php declare(strict_types=1);
22

33
use Nette\Schema\Expect;
4-
use Nette\Schema\Helpers;
54
use Nette\Schema\MergeMode;
65
use Nette\Schema\Processor;
76
use Tester\Assert;
@@ -94,39 +93,6 @@ test('merging default value', function () {
9493
'arr' => ['newitem'],
9594
]),
9695
);
97-
98-
Assert::same(
99-
[
100-
'key1' => 'newval',
101-
'key3' => 'newval',
102-
'newval3',
103-
'arr' => ['newitem'],
104-
],
105-
(new Processor)->process($schema, [
106-
Helpers::PreventMerging => true,
107-
'key1' => 'newval',
108-
'key3' => 'newval',
109-
'newval3',
110-
'arr' => ['newitem'],
111-
]),
112-
);
113-
114-
Assert::same(
115-
[
116-
'key1' => 'newval',
117-
'key2' => 'val2',
118-
'val3',
119-
'arr' => ['newitem'],
120-
'key3' => 'newval',
121-
'newval3',
122-
],
123-
(new Processor)->process($schema, [
124-
'key1' => 'newval',
125-
'key3' => 'newval',
126-
'newval3',
127-
'arr' => [Helpers::PreventMerging => true, 'newitem'],
128-
]),
129-
);
13096
});
13197

13298

0 commit comments

Comments
 (0)