Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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