Skip to content

Commit ef3615c

Browse files
committed
Improved element xsi:type includeTargetNamespace logic
1 parent 36c78e3 commit ef3615c

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

examples/encoders/simpleType/anyType-with-xsi-info.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Soap\Encoding\Encoder\SimpleType\ScalarTypeEncoder;
77
use Soap\Encoding\Encoder\XmlEncoder;
88
use Soap\Encoding\EncoderRegistry;
9-
use Soap\Engine\Metadata\Model\TypeMeta;
109
use Soap\WsdlReader\Model\Definitions\BindingUse;
1110
use VeeWee\Reflecta\Iso\Iso;
1211

@@ -41,17 +40,10 @@ public function iso(Context $context): Iso
4140
/**
4241
* This method allows to change the context on the wrapping elementEncoder.
4342
* By forcing the bindingUse to `ENCODED`, we can make sure the xsi:type attribute is added.
44-
* We also make sure the type is not qualified so that the xsi:type prefix xmlns is imported as well.
4543
*/
4644
public function enhanceElementContext(Context $context): Context
4745
{
48-
return $context
49-
->withBindingUse(BindingUse::ENCODED)
50-
->withType(
51-
$context->type->withMeta(
52-
static fn (TypeMeta $meta): TypeMeta => $meta->withIsQualified(false)
53-
)
54-
);
46+
return $context->withBindingUse(BindingUse::ENCODED);
5547
}
5648
}
5749
);

src/Xml/Writer/ElementValueBuilder.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ private function buildXsiType(XMLWriter $writer): Generator
4747
return;
4848
}
4949

50+
$context = $this->context;
51+
$type = $context->type;
52+
5053
yield from (new XsiAttributeBuilder(
5154
$this->context,
52-
XsiTypeDetector::detectFromValue($this->context, $this->value),
53-
includeXsiTargetNamespace: !$this->context->type->getMeta()->isQualified()->unwrapOr(false)
55+
XsiTypeDetector::detectFromValue($context, $this->value),
56+
includeXsiTargetNamespace: $type->getXmlTargetNamespace() !== $type->getXmlNamespace()
57+
|| !$type->getMeta()->isQualified()->unwrapOr(false)
5458
))($writer);
5559
}
5660

0 commit comments

Comments
 (0)