Skip to content

Commit dcf653e

Browse files
committed
removed support for key PreventMerging (BC break)
1 parent d52aacf commit dcf653e

File tree

4 files changed

+2
-64
lines changed

4 files changed

+2
-64
lines changed

src/Schema/Elements/AnyOf.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ public function normalize(mixed $value, Context $context): mixed
6565

6666
public function merge(mixed $value, mixed $base): mixed
6767
{
68-
if (is_array($value) && isset($value[Helpers::PreventMerging])) {
69-
unset($value[Helpers::PreventMerging]);
70-
return $value;
71-
}
72-
7368
return Helpers::merge($value, $base);
7469
}
7570

src/Schema/Elements/Structure.php

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

9696
public function normalize(mixed $value, Context $context): mixed
9797
{
98-
if ($prevent = (is_array($value) && isset($value[Helpers::PreventMerging]))) {
99-
unset($value[Helpers::PreventMerging]);
100-
}
101-
10298
$value = $this->doNormalize($value, $context);
10399
if (is_object($value)) {
104100
$value = (array) $value;
@@ -113,10 +109,6 @@ public function normalize(mixed $value, Context $context): mixed
113109
array_pop($context->path);
114110
}
115111
}
116-
117-
if ($prevent) {
118-
$value[Helpers::PreventMerging] = true;
119-
}
120112
}
121113

122114
return $value;

src/Schema/Elements/Type.php

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

114114
public function normalize(mixed $value, Context $context): mixed
115115
{
116-
if ($prevent = (is_array($value) && isset($value[Helpers::PreventMerging]))) {
117-
unset($value[Helpers::PreventMerging]);
118-
}
119-
120116
$value = $this->doNormalize($value, $context);
121117
if (is_array($value) && $this->itemsValue) {
122118
$res = [];
@@ -134,18 +130,13 @@ public function normalize(mixed $value, Context $context): mixed
134130
$value = $res;
135131
}
136132

137-
if ($prevent && is_array($value)) {
138-
$value[Helpers::PreventMerging] = true;
139-
}
140-
141133
return $value;
142134
}
143135

144136

145137
public function merge(mixed $value, mixed $base): mixed
146138
{
147-
if ($this->mergeMode === MergeMode::Replace || (is_array($value) && isset($value[Helpers::PreventMerging]))) {
148-
unset($value[Helpers::PreventMerging]);
139+
if ($this->mergeMode === MergeMode::Replace) {
149140
return $value;
150141
}
151142

@@ -171,12 +162,6 @@ public function merge(mixed $value, mixed $base): mixed
171162

172163
public function complete(mixed $value, Context $context): mixed
173164
{
174-
$merge = $this->merge;
175-
if (is_array($value) && isset($value[Helpers::PreventMerging])) {
176-
unset($value[Helpers::PreventMerging]);
177-
$merge = false;
178-
}
179-
180165
if ($value === null && is_array($this->default)) {
181166
$value = []; // is unable to distinguish null from array in NEON
182167
}
@@ -188,7 +173,7 @@ public function complete(mixed $value, Context $context): mixed
188173
$isOk() && Helpers::validateRange($value, $this->range, $context, $this->type);
189174
$isOk() && $value !== null && $this->pattern !== null && Helpers::validatePattern($value, $this->pattern, $context);
190175
$isOk() && is_array($value) && $this->validateItems($value, $context);
191-
$isOk() && $merge && $value = Helpers::merge($value, $this->default);
176+
$isOk() && $this->merge && $value = Helpers::merge($value, $this->default);
192177
$isOk() && $value = $this->doTransform($value, $context);
193178
if (!$isOk()) {
194179
return null;

tests/Schema/Expect.array.phpt

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
declare(strict_types=1);
44

55
use Nette\Schema\Expect;
6-
use Nette\Schema\Helpers;
76
use Nette\Schema\MergeMode;
87
use Nette\Schema\Processor;
98
use Tester\Assert;
@@ -96,39 +95,6 @@ test('merging default value', function () {
9695
'arr' => ['newitem'],
9796
]),
9897
);
99-
100-
Assert::same(
101-
[
102-
'key1' => 'newval',
103-
'key3' => 'newval',
104-
'newval3',
105-
'arr' => ['newitem'],
106-
],
107-
(new Processor)->process($schema, [
108-
Helpers::PreventMerging => true,
109-
'key1' => 'newval',
110-
'key3' => 'newval',
111-
'newval3',
112-
'arr' => ['newitem'],
113-
]),
114-
);
115-
116-
Assert::same(
117-
[
118-
'key1' => 'newval',
119-
'key2' => 'val2',
120-
'val3',
121-
'arr' => ['newitem'],
122-
'key3' => 'newval',
123-
'newval3',
124-
],
125-
(new Processor)->process($schema, [
126-
'key1' => 'newval',
127-
'key3' => 'newval',
128-
'newval3',
129-
'arr' => [Helpers::PreventMerging => true, 'newitem'],
130-
]),
131-
);
13298
});
13399

134100

0 commit comments

Comments
 (0)