1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\WSSecurity\XML\wst_200512; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\WSSecurity\Assert\Assert; |
9
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
10
|
|
|
use SimpleSAML\XML\Exception\MissingElementException; |
11
|
|
|
use SimpleSAML\XML\Exception\TooManyElementsException; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class defining the StatusType element |
15
|
|
|
* |
16
|
|
|
* @package simplesamlphp/ws-security |
17
|
|
|
*/ |
18
|
|
|
abstract class AbstractStatusType extends AbstractWstElement |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* AbstractStatusType constructor |
22
|
|
|
* |
23
|
|
|
* @param \SimpleSAML\WSSecurity\XML\wst_200512\Code $code |
24
|
|
|
* @param \SimpleSAML\WSSecurity\XML\wst_200512\Reason|null $reason |
25
|
|
|
*/ |
26
|
|
|
final public function __construct( |
27
|
|
|
protected Code $code, |
28
|
|
|
protected ?Reason $reason = null, |
29
|
|
|
) { |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return \SimpleSAML\WSSecurity\XML\wst_200512\Code |
35
|
|
|
*/ |
36
|
|
|
public function getCode(): Code |
37
|
|
|
{ |
38
|
|
|
return $this->code; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return \SimpleSAML\WSSecurity\XML\wst_200512\Reason|null |
44
|
|
|
*/ |
45
|
|
|
public function getReason(): ?Reason |
46
|
|
|
{ |
47
|
|
|
return $this->reason; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Create an instance of this object from its XML representation. |
53
|
|
|
* |
54
|
|
|
* @param \DOMElement $xml |
55
|
|
|
* @return static |
56
|
|
|
* |
57
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
58
|
|
|
* if the qualified name of the supplied element is wrong |
59
|
|
|
*/ |
60
|
|
|
public static function fromXML(DOMElement $xml): static |
61
|
|
|
{ |
62
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
|
|
|
|
63
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
64
|
|
|
|
65
|
|
|
$code = Code::getChildrenOfClass($xml); |
66
|
|
|
Assert::minCount($code, 1, MissingElementException::class); |
|
|
|
|
67
|
|
|
Assert::maxCount($code, 1, TooManyElementsException::class); |
|
|
|
|
68
|
|
|
|
69
|
|
|
$reason = Reason::getChildrenOfClass($xml); |
70
|
|
|
Assert::maxCount($reason, 1, TooManyElementsException::class); |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
return new static( |
74
|
|
|
array_pop($code), |
75
|
|
|
array_pop($reason), |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Add this UseKeyType to an XML element. |
82
|
|
|
* |
83
|
|
|
* @param \DOMElement|null $parent The element we should append this username token to. |
84
|
|
|
* @return \DOMElement |
85
|
|
|
*/ |
86
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
87
|
|
|
{ |
88
|
|
|
$e = parent::instantiateParentElement($parent); |
89
|
|
|
|
90
|
|
|
$this->getCode()->toXML($e); |
91
|
|
|
$this->getReason()?->toXML($e); |
92
|
|
|
|
93
|
|
|
return $e; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|