1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\SOAP12\XML; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\SOAP12\Assert\Assert; |
9
|
|
|
use SimpleSAML\XML\Constants as C; |
10
|
|
|
use SimpleSAML\XMLSchema\Exception\{InvalidDOMElementException, SchemaViolationException}; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class representing a env:Reason element. |
14
|
|
|
* |
15
|
|
|
* @package simplesaml/xml-soap |
16
|
|
|
*/ |
17
|
|
|
final class Reason extends AbstractSoapElement |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Initialize a env:Reason |
21
|
|
|
* |
22
|
|
|
* @param \SimpleSAML\SOAP12\XML\Text[] $text |
23
|
|
|
*/ |
24
|
|
|
public function __construct( |
25
|
|
|
protected array $text, |
26
|
|
|
) { |
27
|
|
|
Assert::maxCount($text, C::UNBOUNDED_LIMIT); |
28
|
|
|
Assert::minCount($text, 1, SchemaViolationException::class); |
29
|
|
|
Assert::allIsInstanceOf($text, Text::class, SchemaViolationException::class); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return \SimpleSAML\SOAP12\XML\Text[] |
35
|
|
|
*/ |
36
|
|
|
public function getText(): array |
37
|
|
|
{ |
38
|
|
|
return $this->text; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Convert this element to XML. |
44
|
|
|
* |
45
|
|
|
* @param \DOMElement|null $parent The element we should append this element to. |
46
|
|
|
* @return \DOMElement |
47
|
|
|
*/ |
48
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
49
|
|
|
{ |
50
|
|
|
$e = $this->instantiateParentElement($parent); |
51
|
|
|
|
52
|
|
|
foreach ($this->getText() as $text) { |
53
|
|
|
$text->toXML($e); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $e; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Convert XML into a Value |
61
|
|
|
* |
62
|
|
|
* @param \DOMElement $xml The XML element we should load |
63
|
|
|
* @return static |
64
|
|
|
* |
65
|
|
|
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
66
|
|
|
* If the qualified name of the supplied element is wrong |
67
|
|
|
*/ |
68
|
|
|
public static function fromXML(DOMElement $xml): static |
69
|
|
|
{ |
70
|
|
|
Assert::same($xml->localName, 'Reason', InvalidDOMElementException::class); |
71
|
|
|
Assert::same($xml->namespaceURI, Reason::NS, InvalidDOMElementException::class); |
72
|
|
|
|
73
|
|
|
$text = Text::getChildrenOfClass($xml); |
74
|
|
|
Assert::minCount($text, 1, SchemaViolationException::class); |
75
|
|
|
|
76
|
|
|
return new static($text); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|