|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML11\XML\samlp; |
|
6
|
|
|
|
|
7
|
|
|
use DOMElement; |
|
8
|
|
|
use SimpleSAML\Assert\Assert; |
|
9
|
|
|
use SimpleSAML\SAML11\Constants as C; |
|
10
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* SAML StatusCode data type. |
|
14
|
|
|
* |
|
15
|
|
|
* @package simplesamlphp/saml11 |
|
16
|
|
|
*/ |
|
17
|
|
|
abstract class AbstractStatusCodeType extends AbstractSamlpElement |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Initialize a samlp:StatusCode |
|
21
|
|
|
* |
|
22
|
|
|
* @param string $Value |
|
23
|
|
|
* @param \SimpleSAML\SAML11\XML\samlp\StatusCode[] $subCodes |
|
24
|
|
|
*/ |
|
25
|
|
|
final public function __construct( |
|
26
|
|
|
protected string $Value = C::STATUS_SUCCESS, |
|
27
|
|
|
protected array $subCodes = [], |
|
28
|
|
|
) { |
|
29
|
|
|
Assert::validQName($Value); |
|
30
|
|
|
Assert::maxCount($subCodes, C::UNBOUNDED_LIMIT); |
|
31
|
|
|
Assert::allIsInstanceOf($subCodes, StatusCode::class); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Collect the Value |
|
37
|
|
|
* |
|
38
|
|
|
* @return string |
|
39
|
|
|
*/ |
|
40
|
|
|
public function getValue(): string |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->Value; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Collect the subcodes |
|
48
|
|
|
* |
|
49
|
|
|
* @return \SimpleSAML\SAML11\XML\samlp\StatusCode[] |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getSubCodes(): array |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->subCodes; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Convert XML into a StatusCode |
|
59
|
|
|
* |
|
60
|
|
|
* @param \DOMElement $xml The XML element we should load |
|
61
|
|
|
* @return static |
|
62
|
|
|
* |
|
63
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
|
64
|
|
|
* if the qualified name of the supplied element is wrong |
|
65
|
|
|
* @throws \SimpleSAML\XML\Exception\MissingAttributeException |
|
66
|
|
|
* if the supplied element is missing one of the mandatory attributes |
|
67
|
|
|
*/ |
|
68
|
|
|
public static function fromXML(DOMElement $xml): static |
|
69
|
|
|
{ |
|
70
|
|
|
Assert::same($xml->localName, 'StatusCode', InvalidDOMElementException::class); |
|
71
|
|
|
Assert::same($xml->namespaceURI, StatusCode::NS, InvalidDOMElementException::class); |
|
72
|
|
|
|
|
73
|
|
|
$Value = self::getAttribute($xml, 'Value'); |
|
74
|
|
|
$subCodes = StatusCode::getChildrenOfClass($xml); |
|
75
|
|
|
|
|
76
|
|
|
return new static( |
|
77
|
|
|
$Value, |
|
78
|
|
|
$subCodes, |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Convert this StatusCode to XML. |
|
85
|
|
|
* |
|
86
|
|
|
* @param \DOMElement|null $parent The element we should append this StatusCode to. |
|
87
|
|
|
* @return \DOMElement |
|
88
|
|
|
*/ |
|
89
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
|
90
|
|
|
{ |
|
91
|
|
|
$e = $this->instantiateParentElement($parent); |
|
92
|
|
|
$e->setAttribute('Value', $this->getValue()); |
|
93
|
|
|
|
|
94
|
|
|
foreach ($this->getSubCodes() as $subCode) { |
|
95
|
|
|
$subCode->toXML($e); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return $e; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|