forked from php-soap/encoding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoapEnvelopeReader.php
More file actions
31 lines (25 loc) · 987 Bytes
/
SoapEnvelopeReader.php
File metadata and controls
31 lines (25 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
declare(strict_types=1);
namespace Soap\Encoding\Xml\Reader;
use Soap\Encoding\Fault\Guard\SoapFaultGuard;
use Soap\Encoding\Xml\Node\Element;
use Soap\Xml\Locator\SoapBodyLocator;
use VeeWee\Xml\Dom\Document;
use function VeeWee\Xml\Dom\Assert\assert_element;
use function VeeWee\Xml\Dom\Loader\xml_string_loader;
final class SoapEnvelopeReader
{
/**
* @param non-empty-string $xml
* @param int $libXmlOptions - bitmask of LIBXML_* constants https://www.php.net/manual/en/libxml.constants.php
*/
public function __invoke(string $xml, int $libXmlOptions = 0): Element
{
$envelope = Document::fromLoader(xml_string_loader($xml, $libXmlOptions));
// Make sure it does not contain a fault response before parsing the body parts.
(new SoapFaultGuard())($envelope);
// Locate all body parts:
$body = assert_element($envelope->locate(new SoapBodyLocator()));
return Element::fromDOMElement($body);
}
}