diff --git a/src/Xml/Reader/DocumentToLookupArrayReader.php b/src/Xml/Reader/DocumentToLookupArrayReader.php index 2bbcaa2..1efb076 100644 --- a/src/Xml/Reader/DocumentToLookupArrayReader.php +++ b/src/Xml/Reader/DocumentToLookupArrayReader.php @@ -7,10 +7,12 @@ use DOMNode; use Soap\Encoding\Xml\Node\Element; use Soap\Encoding\Xml\Node\ElementList; +use VeeWee\Xml\Xmlns\Xmlns; use function VeeWee\Xml\Dom\Predicate\is_element; /** - * @psalm-type LookupArray = array + * @psalm-type LookupArrayValue = string|Element|ElementList + * @psalm-type LookupArray = array */ final class DocumentToLookupArrayReader { @@ -20,7 +22,7 @@ final class DocumentToLookupArrayReader public function __invoke(Element $xml): array { $root = $xml->element(); - /** @var array $nodes */ + /** @var LookupArray $nodes */ $nodes = []; // Read all child elements. @@ -38,7 +40,7 @@ public function __invoke(Element $xml): array $currentElement = Element::fromDOMElement($element); // Incrementally build up lists. - /** @var string|Element|ElementList $value */ + /** @var LookupArrayValue $value */ $value = match(true) { $previousValue instanceof ElementList => $previousValue->append($currentElement), $previousValue instanceof Element => new ElementList($previousValue, $currentElement), @@ -50,8 +52,8 @@ public function __invoke(Element $xml): array // It might be possible that the child is a regular textNode. // In that case, we use '_' as the key and the value of the textNode as value. - if (!$nodes && $content = trim($root->textContent)) { - $nodes['_'] = $content; + if (!$nodes && $root->getAttributeNS(Xmlns::xsi()->value(), 'nil') !== 'true') { + $nodes['_'] = $root->textContent; } // All attributes also need to be added as key => value pairs. diff --git a/tests/PhpCompatibility/Schema062Variant1Test.php b/tests/PhpCompatibility/Schema062Variant1Test.php new file mode 100644 index 0000000..4e5f977 --- /dev/null +++ b/tests/PhpCompatibility/Schema062Variant1Test.php @@ -0,0 +1,49 @@ + + + + + + + + EOXML; + protected string $type = 'type="testType"'; + + protected function calculateParam(): mixed + { + return (object)[ + '_' => '', + 'int' => 123 + ]; + } + + protected function expectXml(): string + { + return << + + + + + + + XML; + } +} diff --git a/tests/PhpCompatibility/Schema062Variant2Test.php b/tests/PhpCompatibility/Schema062Variant2Test.php new file mode 100644 index 0000000..f8ab590 --- /dev/null +++ b/tests/PhpCompatibility/Schema062Variant2Test.php @@ -0,0 +1,49 @@ + + + + + + + + EOXML; + protected string $type = 'type="testType"'; + + protected function calculateParam(): mixed + { + return (object)[ + '_' => null, + 'int' => 123 + ]; + } + + protected function expectXml(): string + { + return << + + + + + + + XML; + } +}