Skip to content

Commit

Permalink
removed support for key PreventMerging (BC break)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 6, 2024
1 parent 297db99 commit 997d98a
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 63 deletions.
5 changes: 0 additions & 5 deletions src/Schema/Elements/AnyOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
8 changes: 0 additions & 8 deletions src/Schema/Elements/Structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -112,10 +108,6 @@ public function normalize(mixed $value, Context $context): mixed
array_pop($context->path);
}
}

if ($prevent) {
$value[Helpers::PreventMerging] = true;
}
}

return $value;
Expand Down
19 changes: 2 additions & 17 deletions src/Schema/Elements/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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;
}

Expand All @@ -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
}
Expand All @@ -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;
Expand Down
33 changes: 0 additions & 33 deletions tests/Schema/Expect.array.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -96,39 +96,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'],
]),
);
});


Expand Down

0 comments on commit 997d98a

Please sign in to comment.