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\SOAP12\Constants as C; |
10
|
|
|
use SimpleSAML\XML\Type\LangValue; |
11
|
|
|
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException; |
12
|
|
|
use SimpleSAML\XMLSchema\Exception\MissingAttributeException; |
13
|
|
|
use SimpleSAML\XMLSchema\Type\StringValue; |
14
|
|
|
|
15
|
|
|
use function strval; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class representing a env:Text element. |
19
|
|
|
* |
20
|
|
|
* @package simplesaml/xml-soap |
21
|
|
|
*/ |
22
|
|
|
final class Text extends AbstractSoapElement |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Initialize a env:Text |
26
|
|
|
* |
27
|
|
|
* @param \SimpleSAML\XML\Type\LangValue $language |
28
|
|
|
* @param \SimpleSAML\XMLSchema\Type\StringValue $content |
29
|
|
|
*/ |
30
|
|
|
public function __construct( |
31
|
|
|
protected LangValue $language, |
32
|
|
|
protected StringValue $content, |
33
|
|
|
) { |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Collect the value of the language-property |
39
|
|
|
* |
40
|
|
|
* @return \SimpleSAML\XML\Type\LangValue |
41
|
|
|
*/ |
42
|
|
|
public function getLanguage(): LangValue |
43
|
|
|
{ |
44
|
|
|
return $this->language; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Collect the value of the content-property |
50
|
|
|
* |
51
|
|
|
* @return \SimpleSAML\XMLSchema\Type\StringValue |
52
|
|
|
*/ |
53
|
|
|
public function getContent(): StringValue |
54
|
|
|
{ |
55
|
|
|
return $this->content; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Convert XML into a env:Text element |
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, 'Text', InvalidDOMElementException::class); |
71
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
72
|
|
|
Assert::true( |
73
|
|
|
$xml->hasAttributeNS(C::NS_XML, 'lang'), |
74
|
|
|
'Missing xml:lang from ' . static::getLocalName(), |
75
|
|
|
MissingAttributeException::class, |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
return new static( |
79
|
|
|
LangValue::fromString($xml->getAttributeNS(C::NS_XML, 'lang')), |
80
|
|
|
StringValue::fromString($xml->textContent), |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Convert this Text element to XML. |
87
|
|
|
* |
88
|
|
|
* @param \DOMElement|null $parent The element we should append this Text element to. |
89
|
|
|
* @return \DOMElement |
90
|
|
|
*/ |
91
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
92
|
|
|
{ |
93
|
|
|
$e = $this->instantiateParentElement($parent); |
94
|
|
|
$e->textContent = strval($this->getContent()); |
95
|
|
|
|
96
|
|
|
$this->getLanguage()->toAttribute()->toXML($e); |
97
|
|
|
|
98
|
|
|
return $e; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|