1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\SOAP\XML\env_200106; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
10
|
|
|
use SimpleSAML\XML\Exception\MissingElementException; |
11
|
|
|
use SimpleSAML\XML\Exception\TooManyElementsException; |
12
|
|
|
use SimpleSAML\XML\ExtendableAttributesTrait; |
13
|
|
|
use SimpleSAML\XML\ExtendableElementTrait; |
14
|
|
|
use SimpleSAML\XML\XsNamespace as NS; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class representing a env:Envelope element. |
18
|
|
|
* |
19
|
|
|
* @package simplesaml/xml-soap |
20
|
|
|
*/ |
21
|
|
|
final class Envelope extends AbstractSoapElement |
22
|
|
|
{ |
23
|
|
|
use ExtendableElementTrait; |
|
|
|
|
24
|
|
|
use ExtendableAttributesTrait; |
|
|
|
|
25
|
|
|
|
26
|
|
|
/** The namespace-attribute for the xs:any element */ |
27
|
|
|
public const XS_ANY_ELT_NAMESPACE = NS::OTHER; |
28
|
|
|
|
29
|
|
|
/** The namespace-attribute for the xs:anyAttribute element */ |
30
|
|
|
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER; |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Initialize a env:Envelope |
35
|
|
|
* |
36
|
|
|
* @param \SimpleSAML\SOAP\XML\env_200106\Body $body |
37
|
|
|
* @param \SimpleSAML\SOAP\XML\env_200106\Header|null $header |
38
|
|
|
* @param list<\SimpleSAML\XML\SerializableElementInterface> $children |
39
|
|
|
* @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes |
|
|
|
|
40
|
|
|
*/ |
41
|
|
|
public function __construct( |
42
|
|
|
protected Body $body, |
43
|
|
|
protected ?Header $header = null, |
44
|
|
|
array $children = [], |
45
|
|
|
array $namespacedAttributes = [], |
46
|
|
|
) { |
47
|
|
|
$this->setElements($children); |
48
|
|
|
$this->setAttributesNS($namespacedAttributes); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return \SimpleSAML\SOAP\XML\env_200106\Body |
54
|
|
|
*/ |
55
|
|
|
public function getBody(): Body |
56
|
|
|
{ |
57
|
|
|
return $this->body; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return \SimpleSAML\SOAP\XML\env_200106\Header|null |
63
|
|
|
*/ |
64
|
|
|
public function getHeader(): ?Header |
65
|
|
|
{ |
66
|
|
|
return $this->header; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Convert XML into an Envelope element |
72
|
|
|
* |
73
|
|
|
* @param \DOMElement $xml The XML element we should load |
74
|
|
|
* @return static |
75
|
|
|
* |
76
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
77
|
|
|
* If the qualified name of the supplied element is wrong |
78
|
|
|
*/ |
79
|
|
|
public static function fromXML(DOMElement $xml): static |
80
|
|
|
{ |
81
|
|
|
Assert::same($xml->localName, 'Envelope', InvalidDOMElementException::class); |
82
|
|
|
Assert::same($xml->namespaceURI, Envelope::NS, InvalidDOMElementException::class); |
83
|
|
|
|
84
|
|
|
$body = Body::getChildrenOfClass($xml); |
85
|
|
|
Assert::count($body, 1, 'Must contain exactly one Body', MissingElementException::class); |
86
|
|
|
|
87
|
|
|
$header = Header::getChildrenOfClass($xml); |
88
|
|
|
Assert::maxCount($header, 1, 'Cannot process more than one Header element.', TooManyElementsException::class); |
89
|
|
|
|
90
|
|
|
return new static( |
91
|
|
|
array_pop($body), |
92
|
|
|
empty($header) ? null : array_pop($header), |
93
|
|
|
self::getChildElementsFromXML($xml), |
94
|
|
|
self::getAttributesNSFromXML($xml), |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Convert this Envelope to XML. |
101
|
|
|
* |
102
|
|
|
* @param \DOMElement|null $parent The element we should add this envelope to. |
103
|
|
|
* @return \DOMElement This Envelope-element. |
104
|
|
|
*/ |
105
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
106
|
|
|
{ |
107
|
|
|
$e = $this->instantiateParentElement($parent); |
108
|
|
|
|
109
|
|
|
foreach ($this->getAttributesNS() as $attr) { |
110
|
|
|
$attr->toXML($e); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
if ($this->getHeader() !== null && !$this->getHeader()->isEmptyElement()) { |
114
|
|
|
$this->getHeader()->toXML($e); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
$this->getBody()->toXML($e); |
118
|
|
|
|
119
|
|
|
/** @psalm-var \SimpleSAML\XML\SerializableElementInterface $child */ |
120
|
|
|
foreach ($this->getElements() as $child) { |
121
|
|
|
if (!$child->isEmptyElement()) { |
122
|
|
|
$child->toXML($e); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
return $e; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|