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\XML\Exception\InvalidDOMElementException; |
10
|
|
|
use SimpleSAML\XML\Exception\MissingElementException; |
11
|
|
|
use SimpleSAML\XML\Exception\TooManyElementsException; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class representing a env:Fault element. |
15
|
|
|
* |
16
|
|
|
* @package simplesaml/xml-soap |
17
|
|
|
*/ |
18
|
|
|
final class Fault extends AbstractSoapElement |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Initialize a env:Fault |
22
|
|
|
* |
23
|
|
|
* @param \SimpleSAML\SOAP12\XML\env\Code $code |
24
|
|
|
* @param \SimpleSAML\SOAP12\XML\env\Reason $reason |
25
|
|
|
* @param \SimpleSAML\SOAP12\XML\env\Node|null $node |
26
|
|
|
* @param \SimpleSAML\SOAP12\XML\env\Role|null $role |
27
|
|
|
* @param \SimpleSAML\SOAP12\XML\env\Detail|null $detail |
28
|
|
|
*/ |
29
|
|
|
public function __construct( |
30
|
|
|
protected Code $code, |
31
|
|
|
protected Reason $reason, |
32
|
|
|
protected ?Node $node = null, |
33
|
|
|
protected ?Role $role = null, |
34
|
|
|
protected ?Detail $detail = null |
35
|
|
|
) { |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return \SimpleSAML\SOAP12\XML\env\Code |
41
|
|
|
*/ |
42
|
|
|
public function getCode(): Code |
43
|
|
|
{ |
44
|
|
|
return $this->code; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return \SimpleSAML\SOAP12\XML\env\Reason |
50
|
|
|
*/ |
51
|
|
|
public function getReason(): Reason |
52
|
|
|
{ |
53
|
|
|
return $this->reason; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return \SimpleSAML\SOAP12\XML\env\Node|null |
59
|
|
|
*/ |
60
|
|
|
public function getNode(): ?Node |
61
|
|
|
{ |
62
|
|
|
return $this->node; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return \SimpleSAML\SOAP12\XML\env\Role|null |
68
|
|
|
*/ |
69
|
|
|
public function getRole(): ?Role |
70
|
|
|
{ |
71
|
|
|
return $this->role; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return \SimpleSAML\SOAP12\XML\env\Detail|null |
77
|
|
|
*/ |
78
|
|
|
public function getDetail(): ?Detail |
79
|
|
|
{ |
80
|
|
|
return $this->detail; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Convert XML into an Fault 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, 'Fault', InvalidDOMElementException::class); |
96
|
|
|
Assert::same($xml->namespaceURI, Fault::NS, InvalidDOMElementException::class); |
97
|
|
|
|
98
|
|
|
$code = Code::getChildrenOfClass($xml); |
99
|
|
|
Assert::count($code, 1, 'Must contain exactly one Code', MissingElementException::class); |
100
|
|
|
|
101
|
|
|
$reason = Reason::getChildrenOfClass($xml); |
102
|
|
|
Assert::count($reason, 1, 'Must contain exactly one Reason', MissingElementException::class); |
103
|
|
|
|
104
|
|
|
$node = Node::getChildrenOfClass($xml); |
105
|
|
|
Assert::maxCount($node, 1, 'Cannot process more than one Node element.', TooManyElementsException::class); |
106
|
|
|
|
107
|
|
|
$role = Role::getChildrenOfClass($xml); |
108
|
|
|
Assert::maxCount($role, 1, 'Cannot process more than one Role element.', TooManyElementsException::class); |
109
|
|
|
|
110
|
|
|
$detail = Detail::getChildrenOfClass($xml); |
111
|
|
|
Assert::maxCount($detail, 1, 'Cannot process more than one Detail element.', TooManyElementsException::class); |
112
|
|
|
|
113
|
|
|
return new self( |
114
|
|
|
array_pop($code), |
115
|
|
|
array_pop($reason), |
116
|
|
|
empty($node) ? null : array_pop($node), |
117
|
|
|
empty($role) ? null : array_pop($role), |
118
|
|
|
empty($detail) ? null : array_pop($detail) |
119
|
|
|
); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Convert this Fault to XML. |
125
|
|
|
* |
126
|
|
|
* @param \DOMElement|null $parent The element we should add this fault to. |
127
|
|
|
* @return \DOMElement This Fault-element. |
128
|
|
|
*/ |
129
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
130
|
|
|
{ |
131
|
|
|
$e = $this->instantiateParentElement($parent); |
132
|
|
|
|
133
|
|
|
$this->getCode()->toXML($e); |
134
|
|
|
$this->getReason()->toXML($e); |
135
|
|
|
|
136
|
|
|
$this->getNode()?->toXML($e); |
137
|
|
|
$this->getRole()?->toXML($e); |
138
|
|
|
|
139
|
|
|
if ($this->getDetail() !== null && !$this->getDetail()->isEmptyElement()) { |
140
|
|
|
$this->getDetail()->toXML($e); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
return $e; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|