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