Skip to content

Commit

Permalink
Merge pull request #36 from veewee/rpc-reader-fix
Browse files Browse the repository at this point in the history
Fix reading RPC responses
  • Loading branch information
veewee authored Feb 7, 2025
2 parents 3265f1c + d807dac commit 29c2389
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/Xml/Reader/OperationReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use Soap\Engine\Metadata\Model\MethodMeta;
use Soap\WsdlReader\Model\Definitions\BindingStyle;
use function Psl\Vec\map;
use function VeeWee\Xml\Dom\Assert\assert_element;
use function VeeWee\Xml\Dom\Locator\Element\children as locateChildElements;
use function VeeWee\Xml\Dom\Xpath\Configurator\namespaces;

final class OperationReader
{
Expand All @@ -25,21 +25,16 @@ public function __construct(
*/
public function __invoke(string $xml): ElementList
{
$operationName = $this->meta->operationName()->unwrap();
$namespace = $this->meta->outputNamespace()->or($this->meta->targetNamespace())->unwrap();
$bindingStyle = BindingStyle::tryFrom($this->meta->bindingStyle()->unwrapOr(BindingStyle::DOCUMENT->value));

// The Response can contain out of multiple response parts.
// Therefore, it is being wrapped by a central root element:
$body = (new SoapEnvelopeReader())($xml);
$bodyElement = $body->element();
$xpath = $body->document()->xpath(namespaces(['tns' => $namespace]));

$elements = match($bindingStyle) {
BindingStyle::DOCUMENT => locateChildElements($bodyElement),
BindingStyle::RPC => locateChildElements(
$xpath->querySingle('./tns:'.$operationName, $bodyElement)
)
BindingStyle::RPC => locateChildElements(assert_element($bodyElement->firstElementChild)),
};

return new ElementList(...map($elements, Element::fromDOMElement(...)));
Expand Down

0 comments on commit 29c2389

Please sign in to comment.