|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\SOAP\XML\env_200305; |
|
6
|
|
|
|
|
7
|
|
|
use DOMElement; |
|
8
|
|
|
use SimpleSAML\Assert\Assert; |
|
9
|
|
|
use SimpleSAML\SOAP\Exception\ProtocolViolationException; |
|
10
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
|
11
|
|
|
use SimpleSAML\XML\ExtendableAttributesTrait; |
|
12
|
|
|
use SimpleSAML\XML\ExtendableElementTrait; |
|
13
|
|
|
use SimpleSAML\XML\XsNamespace as NS; |
|
14
|
|
|
|
|
15
|
|
|
use function array_pop; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class representing a env:Body element. |
|
19
|
|
|
* |
|
20
|
|
|
* @package simplesaml/xml-soap |
|
21
|
|
|
*/ |
|
22
|
|
|
final class Body extends AbstractSoapElement |
|
23
|
|
|
{ |
|
24
|
|
|
use ExtendableAttributesTrait; |
|
|
|
|
|
|
25
|
|
|
use ExtendableElementTrait; |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** The namespace-attribute for the xs:any element */ |
|
28
|
|
|
public const XS_ANY_ELT_NAMESPACE = NS::ANY; |
|
29
|
|
|
|
|
30
|
|
|
/** The namespace-attribute for the xs:anyAttribute element */ |
|
31
|
|
|
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER; |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Initialize a soap:Body |
|
36
|
|
|
* |
|
37
|
|
|
* @param \SimpleSAML\SOAP\XML\env_200305\Fault|null $fault |
|
38
|
|
|
* @param list<\SimpleSAML\XML\SerializableElementInterface> $children |
|
39
|
|
|
* @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes |
|
|
|
|
|
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct( |
|
42
|
|
|
protected ?Fault $fault = null, |
|
43
|
|
|
array $children = [], |
|
44
|
|
|
array $namespacedAttributes = [], |
|
45
|
|
|
) { |
|
46
|
|
|
if ($fault !== null) { |
|
47
|
|
|
/** |
|
48
|
|
|
* 5.4: When generating a fault, SOAP senders MUST NOT include additional element |
|
49
|
|
|
* information items in the SOAP Body . |
|
50
|
|
|
*/ |
|
51
|
|
|
Assert::isEmpty( |
|
52
|
|
|
$children, |
|
53
|
|
|
"When generating a fault, SOAP senders MUST NOT include additional elements in the SOAP Body.", |
|
54
|
|
|
ProtocolViolationException::class, |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
Assert::allNotInstanceOf($children, Fault::class, ProtocolViolationException::class); |
|
58
|
|
|
|
|
59
|
|
|
$this->setElements($children); |
|
60
|
|
|
$this->setAttributesNS($namespacedAttributes); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return \SimpleSAML\SOAP\XML\env_200305\Fault|null |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getFault(): ?Fault |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->fault; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Test if an object, at the state it's in, would produce an empty XML-element |
|
75
|
|
|
* |
|
76
|
|
|
* @return bool |
|
77
|
|
|
*/ |
|
78
|
|
|
public function isEmptyElement(): bool |
|
79
|
|
|
{ |
|
80
|
|
|
return empty($this->fault) && empty($this->elements) && empty($this->namespacedAttributes); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
/* |
|
85
|
|
|
* Convert XML into an Body element |
|
86
|
|
|
* |
|
87
|
|
|
* @param \DOMElement $xml The XML element we should load |
|
88
|
|
|
* @return static |
|
89
|
|
|
* |
|
90
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
|
91
|
|
|
* If the qualified name of the supplied element is wrong |
|
92
|
|
|
*/ |
|
93
|
|
|
public static function fromXML(DOMElement $xml): static |
|
94
|
|
|
{ |
|
95
|
|
|
Assert::same($xml->localName, 'Body', InvalidDOMElementException::class); |
|
96
|
|
|
Assert::same($xml->namespaceURI, Body::NS, InvalidDOMElementException::class); |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* 5.4: To be recognized as carrying SOAP error information, a SOAP message MUST contain a single SOAP Fault |
|
100
|
|
|
* element information item as the only child element information item of the SOAP Body . |
|
101
|
|
|
*/ |
|
102
|
|
|
$fault = Fault::getChildrenOfClass($xml); |
|
103
|
|
|
Assert::maxCount($fault, 1, ProtocolViolationException::class); |
|
104
|
|
|
|
|
105
|
|
|
return new static( |
|
106
|
|
|
array_pop($fault), |
|
107
|
|
|
self::getChildElementsFromXML($xml), |
|
108
|
|
|
self::getAttributesNSFromXML($xml), |
|
109
|
|
|
); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Convert this Body to XML. |
|
115
|
|
|
* |
|
116
|
|
|
* @param \DOMElement|null $parent The element we should add this Body to. |
|
117
|
|
|
* @return \DOMElement This Body-element. |
|
118
|
|
|
*/ |
|
119
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
|
120
|
|
|
{ |
|
121
|
|
|
$e = $this->instantiateParentElement($parent); |
|
122
|
|
|
|
|
123
|
|
|
foreach ($this->getAttributesNS() as $attr) { |
|
124
|
|
|
$attr->toXML($e); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
$this->getFault()?->toXML($e); |
|
128
|
|
|
|
|
129
|
|
|
/** @psalm-var \SimpleSAML\XML\SerializableElementInterface $child */ |
|
130
|
|
|
foreach ($this->getElements() as $child) { |
|
131
|
|
|
$child->toXML($e); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
return $e; |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|