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