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