Skip to content

Commit

Permalink
Merge pull request #20 from veewee/improved-include-xsi-target-logic
Browse files Browse the repository at this point in the history
Improved element xsi:type includeTargetNamespace logic
  • Loading branch information
veewee authored Aug 1, 2024
2 parents 36c78e3 + ef3615c commit abbf352
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
10 changes: 1 addition & 9 deletions examples/encoders/simpleType/anyType-with-xsi-info.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Soap\Encoding\Encoder\SimpleType\ScalarTypeEncoder;
use Soap\Encoding\Encoder\XmlEncoder;
use Soap\Encoding\EncoderRegistry;
use Soap\Engine\Metadata\Model\TypeMeta;
use Soap\WsdlReader\Model\Definitions\BindingUse;
use VeeWee\Reflecta\Iso\Iso;

Expand Down Expand Up @@ -41,17 +40,10 @@ public function iso(Context $context): Iso
/**
* This method allows to change the context on the wrapping elementEncoder.
* By forcing the bindingUse to `ENCODED`, we can make sure the xsi:type attribute is added.
* We also make sure the type is not qualified so that the xsi:type prefix xmlns is imported as well.
*/
public function enhanceElementContext(Context $context): Context
{
return $context
->withBindingUse(BindingUse::ENCODED)
->withType(
$context->type->withMeta(
static fn (TypeMeta $meta): TypeMeta => $meta->withIsQualified(false)
)
);
return $context->withBindingUse(BindingUse::ENCODED);
}
}
);
8 changes: 6 additions & 2 deletions src/Xml/Writer/ElementValueBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ private function buildXsiType(XMLWriter $writer): Generator
return;
}

$context = $this->context;
$type = $context->type;

yield from (new XsiAttributeBuilder(
$this->context,
XsiTypeDetector::detectFromValue($this->context, $this->value),
includeXsiTargetNamespace: !$this->context->type->getMeta()->isQualified()->unwrapOr(false)
XsiTypeDetector::detectFromValue($context, $this->value),
includeXsiTargetNamespace: $type->getXmlTargetNamespace() !== $type->getXmlNamespace()
|| !$type->getMeta()->isQualified()->unwrapOr(false)
))($writer);
}

Expand Down

0 comments on commit abbf352

Please sign in to comment.