|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\WSSecurity\XML\wst_200502; |
|
6
|
|
|
|
|
7
|
|
|
use DOMElement; |
|
8
|
|
|
use SimpleSAML\WSSecurity\Assert\Assert; |
|
9
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
|
10
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
|
11
|
|
|
use SimpleSAML\XML\ExtendableAttributesTrait; |
|
12
|
|
|
use SimpleSAML\XML\StringElementTrait; |
|
13
|
|
|
use SimpleSAML\XML\XsNamespace as NS; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* A BinaryExchangeType element |
|
17
|
|
|
* |
|
18
|
|
|
* @package simplesamlphp/ws-security |
|
19
|
|
|
*/ |
|
20
|
|
|
abstract class AbstractBinaryExchangeType extends AbstractWstElement |
|
21
|
|
|
{ |
|
22
|
|
|
use ExtendableAttributesTrait; |
|
23
|
|
|
use StringElementTrait; |
|
24
|
|
|
|
|
25
|
|
|
/** The namespace-attribute for the xs:anyAttribute element */ |
|
26
|
|
|
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER; |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param string $content |
|
31
|
|
|
* @param string $valueType |
|
32
|
|
|
* @param string $encodingType |
|
33
|
|
|
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes |
|
34
|
|
|
*/ |
|
35
|
|
|
final public function __construct( |
|
36
|
|
|
string $content, |
|
37
|
|
|
protected string $valueType, |
|
38
|
|
|
protected string $encodingType, |
|
39
|
|
|
array $namespacedAttributes, |
|
40
|
|
|
) { |
|
41
|
|
|
Assert::validURI($valueType, SchemaViolationException::class); |
|
42
|
|
|
Assert::validURI($encodingType, SchemaViolationException::class); |
|
43
|
|
|
|
|
44
|
|
|
$this->setContent($content); |
|
45
|
|
|
$this->setAttributesNS($namespacedAttributes); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Get the valueType property. |
|
51
|
|
|
* |
|
52
|
|
|
* @return string |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getValueType(): string |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->valueType; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get the valueType property. |
|
62
|
|
|
* |
|
63
|
|
|
* @return string |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getEncodingType(): string |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->encodingType; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Convert XML into a class instance |
|
73
|
|
|
* |
|
74
|
|
|
* @param \DOMElement $xml The XML element we should load |
|
75
|
|
|
* @return static |
|
76
|
|
|
* |
|
77
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
|
78
|
|
|
* If the qualified name of the supplied element is wrong |
|
79
|
|
|
*/ |
|
80
|
|
|
public static function fromXML(DOMElement $xml): static |
|
81
|
|
|
{ |
|
82
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
|
83
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
|
84
|
|
|
|
|
85
|
|
|
return new static( |
|
86
|
|
|
$xml->textContent, |
|
87
|
|
|
self::getAttribute($xml, 'ValueType'), |
|
88
|
|
|
self::getAttribute($xml, 'EncodingType'), |
|
89
|
|
|
self::getAttributesNSFromXML($xml), |
|
90
|
|
|
); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Convert this element to XML. |
|
96
|
|
|
* |
|
97
|
|
|
* @param \DOMElement|null $parent The element we should append this element to. |
|
98
|
|
|
* @return \DOMElement |
|
99
|
|
|
*/ |
|
100
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
|
101
|
|
|
{ |
|
102
|
|
|
$e = $this->instantiateParentElement($parent); |
|
103
|
|
|
$e->textContent = $this->getContent(); |
|
104
|
|
|
|
|
105
|
|
|
$e->setAttribute('ValueType', $this->getValueType()); |
|
106
|
|
|
$e->setAttribute('EncodingType', $this->getEncodingType()); |
|
107
|
|
|
|
|
108
|
|
|
foreach ($this->getAttributesNS() as $attr) { |
|
109
|
|
|
$attr->toXML($e); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
return $e; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|