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\SchemaValidatableElementInterface; |
13
|
|
|
use SimpleSAML\XML\SchemaValidatableElementTrait; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class representing a env:Fault element. |
17
|
|
|
* |
18
|
|
|
* @package simplesaml/xml-soap |
19
|
|
|
*/ |
20
|
|
|
final class Fault extends AbstractSoapElement implements SchemaValidatableElementInterface |
21
|
|
|
{ |
22
|
|
|
use SchemaValidatableElementTrait; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Initialize a env:Fault |
26
|
|
|
* |
27
|
|
|
* @param \SimpleSAML\SOAP\XML\env_200106\FaultCode $faultCode |
28
|
|
|
* @param \SimpleSAML\SOAP\XML\env_200106\FaultString $faultString |
29
|
|
|
* @param \SimpleSAML\SOAP\XML\env_200106\FaultActor|null $faultActor |
30
|
|
|
* @param \SimpleSAML\SOAP\XML\env_200106\Detail|null $detail |
31
|
|
|
*/ |
32
|
|
|
public function __construct( |
33
|
|
|
protected FaultCode $faultCode, |
34
|
|
|
protected FaultString $faultString, |
35
|
|
|
protected ?FaultActor $faultActor = null, |
36
|
|
|
protected ?Detail $detail = null, |
37
|
|
|
) { |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return \SimpleSAML\SOAP\XML\env_200106\FaultCode |
43
|
|
|
*/ |
44
|
|
|
public function getFaultCode(): FaultCode |
45
|
|
|
{ |
46
|
|
|
return $this->faultCode; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return \SimpleSAML\SOAP\XML\env_200106\FaultString |
52
|
|
|
*/ |
53
|
|
|
public function getFaultString(): FaultString |
54
|
|
|
{ |
55
|
|
|
return $this->faultString; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return \SimpleSAML\SOAP\XML\env_200106\FaultActor|null |
61
|
|
|
*/ |
62
|
|
|
public function getFaultActor(): ?FaultActor |
63
|
|
|
{ |
64
|
|
|
return $this->faultActor; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return \SimpleSAML\SOAP\XML\env_200106\Detail|null |
70
|
|
|
*/ |
71
|
|
|
public function getDetail(): ?Detail |
72
|
|
|
{ |
73
|
|
|
return $this->detail; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Convert XML into an Fault element |
79
|
|
|
* |
80
|
|
|
* @param \DOMElement $xml The XML element we should load |
81
|
|
|
* @return static |
82
|
|
|
* |
83
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
84
|
|
|
* If the qualified name of the supplied element is wrong |
85
|
|
|
*/ |
86
|
|
|
public static function fromXML(DOMElement $xml): static |
87
|
|
|
{ |
88
|
|
|
Assert::same($xml->localName, 'Fault', InvalidDOMElementException::class); |
89
|
|
|
Assert::same($xml->namespaceURI, Fault::NS, InvalidDOMElementException::class); |
90
|
|
|
|
91
|
|
|
$faultCode = FaultCode::getChildrenOfClass($xml); |
92
|
|
|
Assert::count($faultCode, 1, 'Must contain exactly one faultcode', MissingElementException::class); |
93
|
|
|
|
94
|
|
|
$faultString = FaultString::getChildrenOfClass($xml); |
95
|
|
|
Assert::count($faultString, 1, 'Must contain exactly one faultstring', MissingElementException::class); |
96
|
|
|
|
97
|
|
|
$faultActor = FaultActor::getChildrenOfClass($xml); |
98
|
|
|
Assert::maxCount( |
99
|
|
|
$faultActor, |
100
|
|
|
1, |
101
|
|
|
'Cannot process more than one faultactor element.', |
102
|
|
|
TooManyElementsException::class, |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
$detail = Detail::getChildrenOfClass($xml); |
106
|
|
|
Assert::maxCount($detail, 1, 'Cannot process more than one detail element.', TooManyElementsException::class); |
107
|
|
|
|
108
|
|
|
return new self( |
109
|
|
|
array_pop($faultCode), |
110
|
|
|
array_pop($faultString), |
111
|
|
|
array_pop($faultActor), |
112
|
|
|
array_pop($detail), |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Convert this Fault to XML. |
119
|
|
|
* |
120
|
|
|
* @param \DOMElement|null $parent The element we should add this fault to. |
121
|
|
|
* @return \DOMElement This Fault-element. |
122
|
|
|
*/ |
123
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
124
|
|
|
{ |
125
|
|
|
$e = $this->instantiateParentElement($parent); |
126
|
|
|
|
127
|
|
|
$this->getFaultCode()->toXML($e); |
128
|
|
|
$this->getFaultString()->toXML($e); |
129
|
|
|
$this->getFaultActor()?->toXML($e); |
130
|
|
|
|
131
|
|
|
if ($this->getDetail() !== null && !$this->getDetail()->isEmptyElement()) { |
132
|
|
|
$this->getDetail()->toXML($e); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
return $e; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|