Skip to content

Commit 0cf3ef4

Browse files
committed
Restore comments and simplify from() to return Iso from match
1 parent 14244e5 commit 0cf3ef4

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/Encoder/XsiTypeEncoder.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,21 @@ function (string|Element $value) use ($context, $innerIso) : mixed {
4343

4444
private function to(Iso $innerIso, mixed $value): string
4545
{
46+
// There is no way to know what xsi:type to use when encoding any type.
47+
// The type defined in the wsdl will always be used to encode the value.
48+
// If you want more control over the encoded type, please control how to encode by using the MatchingValueEncoder.
4649
return $innerIso->to($value);
4750
}
4851

4952
private function from(Context $context, Iso $innerIso, Element $value): mixed
5053
{
51-
/** @var XmlEncoder<string, mixed> $encoder */
52-
$encoder = match (true) {
53-
$this->encoder instanceof Feature\DisregardXsiInformation => $this->encoder,
54-
default => XsiTypeDetector::detectEncoderFromXmlElement($context, $value->element())->unwrapOr($this->encoder)
54+
$iso = match (true) {
55+
$this->encoder instanceof Feature\DisregardXsiInformation => $innerIso,
56+
default => XsiTypeDetector::detectEncoderFromXmlElement($context, $value->element())
57+
->map(static fn (XmlEncoder $encoder): Iso => $encoder->iso($context))
58+
->unwrapOr($innerIso),
5559
};
5660

57-
$iso = $encoder === $this->encoder ? $innerIso : $encoder->iso($context);
58-
5961
return $iso->from($value);
6062
}
6163
}

0 commit comments

Comments
 (0)