Skip to content

Commit 746adc2

Browse files
committed
removed support for key PreventMerging (BC break)
1 parent 3e640f5 commit 746adc2

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
final class AnyOf implements Schema
@@ -64,11 +64,6 @@ public function normalize(mixed $value, Context $context): mixed
6464

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

src/Schema/Elements/Structure.php

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

9494
public function normalize(mixed $value, Context $context): mixed
9595
{
96-
if ($prevent = (is_array($value) && isset($value[Helpers::PreventMerging]))) {
97-
unset($value[Helpers::PreventMerging]);
98-
}
99-
10096
$value = $this->doNormalize($value, $context);
10197
if (is_object($value)) {
10298
$value = (array) $value;
@@ -111,10 +107,6 @@ public function normalize(mixed $value, Context $context): mixed
111107
array_pop($context->path);
112108
}
113109
}
114-
115-
if ($prevent) {
116-
$value[Helpers::PreventMerging] = true;
117-
}
118110
}
119111

120112
return $value;

src/Schema/Elements/Type.php

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

112112
public function normalize(mixed $value, Context $context): mixed
113113
{
114-
if ($prevent = (is_array($value) && isset($value[Helpers::PreventMerging]))) {
115-
unset($value[Helpers::PreventMerging]);
116-
}
117-
118114
$value = $this->doNormalize($value, $context);
119115
if (is_array($value) && $this->itemsValue) {
120116
$res = [];
@@ -132,18 +128,13 @@ public function normalize(mixed $value, Context $context): mixed
132128
$value = $res;
133129
}
134130

135-
if ($prevent && is_array($value)) {
136-
$value[Helpers::PreventMerging] = true;
137-
}
138-
139131
return $value;
140132
}
141133

142134

143135
public function merge(mixed $value, mixed $base): mixed
144136
{
145-
if ($this->mergeMode === MergeMode::Replace || (is_array($value) && isset($value[Helpers::PreventMerging]))) {
146-
unset($value[Helpers::PreventMerging]);
137+
if ($this->mergeMode === MergeMode::Replace) {
147138
return $value;
148139
}
149140

@@ -169,12 +160,6 @@ public function merge(mixed $value, mixed $base): mixed
169160

170161
public function complete(mixed $value, Context $context): mixed
171162
{
172-
$merge = $this->merge;
173-
if (is_array($value) && isset($value[Helpers::PreventMerging])) {
174-
unset($value[Helpers::PreventMerging]);
175-
$merge = false;
176-
}
177-
178163
if ($value === null && is_array($this->default)) {
179164
$value = []; // is unable to distinguish null from array in NEON
180165
}
@@ -186,7 +171,7 @@ public function complete(mixed $value, Context $context): mixed
186171
$isOk() && Helpers::validateRange($value, $this->range, $context, $this->type);
187172
$isOk() && $value !== null && $this->pattern !== null && Helpers::validatePattern($value, $this->pattern, $context);
188173
$isOk() && is_array($value) && $this->validateItems($value, $context);
189-
$isOk() && $merge && $value = Helpers::merge($value, $this->default);
174+
$isOk() && $this->merge && $value = Helpers::merge($value, $this->default);
190175
$isOk() && $value = $this->doTransform($value, $context);
191176
if (!$isOk()) {
192177
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)