1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\SOAP12\XML\env; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\SOAP\Constants as C; |
10
|
|
|
use SimpleSAML\XML\Chunk; |
11
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
12
|
|
|
use SimpleSAML\XML\ExtendableElementTrait; |
13
|
|
|
use SimpleSAML\XML\ExtendableAttributesTrait; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class representing a env:Body element. |
17
|
|
|
* |
18
|
|
|
* @package simplesaml/xml-soap |
19
|
|
|
*/ |
20
|
|
|
final class Body extends AbstractSoapElement |
21
|
|
|
{ |
22
|
|
|
use ExtendableAttributesTrait; |
23
|
|
|
use ExtendableElementTrait; |
24
|
|
|
|
25
|
|
|
/** The namespace-attribute for the xs:any element */ |
26
|
|
|
public const NAMESPACE = C::XS_ANY_NS_ANY; |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Initialize a soap:Body |
31
|
|
|
* |
32
|
|
|
* @param \SimpleSAML\XML\Chunk[] $children |
33
|
|
|
* @param \DOMAttr[] $namespacedAttributes |
34
|
|
|
*/ |
35
|
|
|
public function __construct(array $children = [], array $namespacedAttributes = []) |
36
|
|
|
{ |
37
|
|
|
$this->setElements($children); |
38
|
|
|
$this->setAttributesNS($namespacedAttributes); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Test if an object, at the state it's in, would produce an empty XML-element |
44
|
|
|
* |
45
|
|
|
* @return bool |
46
|
|
|
*/ |
47
|
|
|
public function isEmptyElement(): bool |
48
|
|
|
{ |
49
|
|
|
return empty($this->elements) && empty($this->namespacedAttributes); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
/* |
54
|
|
|
* Convert XML into an Body element |
55
|
|
|
* |
56
|
|
|
* @param \DOMElement $xml The XML element we should load |
57
|
|
|
* @return static |
58
|
|
|
* |
59
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
60
|
|
|
* If the qualified name of the supplied element is wrong |
61
|
|
|
*/ |
62
|
|
|
public static function fromXML(DOMElement $xml): static |
63
|
|
|
{ |
64
|
|
|
Assert::same($xml->localName, 'Body', InvalidDOMElementException::class); |
65
|
|
|
Assert::same($xml->namespaceURI, Body::NS, InvalidDOMElementException::class); |
66
|
|
|
|
67
|
|
|
$children = []; |
68
|
|
|
foreach ($xml->childNodes as $child) { |
69
|
|
|
if (!($child instanceof DOMElement)) { |
70
|
|
|
continue; |
71
|
|
|
} elseif ($child->namespaceURI === C::NS_SOAP_ENV_12) { |
72
|
|
|
if ($child->localName === 'Fault') { |
73
|
|
|
Fault::fromXML($child); |
74
|
|
|
continue; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
$children[] = new Chunk($child); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return new static( |
81
|
|
|
$children, |
82
|
|
|
self::getAttributesNSFromXML($xml) |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Convert this Body to XML. |
89
|
|
|
* |
90
|
|
|
* @param \DOMElement|null $parent The element we should add this Body to. |
91
|
|
|
* @return \DOMElement This Body-element. |
92
|
|
|
*/ |
93
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
94
|
|
|
{ |
95
|
|
|
$e = $this->instantiateParentElement($parent); |
96
|
|
|
|
97
|
|
|
foreach ($this->getAttributesNS() as $attr) { |
98
|
|
|
$e->setAttributeNS($attr['namespaceURI'], $attr['qualifiedName'], $attr['value']); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** @psalm-var \SimpleSAML\XML\SerializableElementInterface $child */ |
102
|
|
|
foreach ($this->getElements() as $child) { |
103
|
|
|
$child->toXML($e); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return $e; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|