1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\WSSecurity\XML\wst_200512; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\WSSecurity\Assert\Assert; |
9
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
10
|
|
|
use SimpleSAML\XML\ExtendableElementTrait; |
11
|
|
|
use SimpleSAML\XML\XsNamespace as NS; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class defining the KeyExchangeTokenType element |
15
|
|
|
* |
16
|
|
|
* @package simplesamlphp/ws-security |
17
|
|
|
*/ |
18
|
|
|
abstract class AbstractKeyExchangeTokenType extends AbstractWstElement |
19
|
|
|
{ |
20
|
|
|
use ExtendableElementTrait; |
|
|
|
|
21
|
|
|
|
22
|
|
|
/** The namespace-attribute for the xs:any element */ |
23
|
|
|
public const XS_ANY_ELT_NAMESPACE = NS::ANY; |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* AbstractKeyExchangeTokenType constructor |
28
|
|
|
* |
29
|
|
|
* @param array<\SimpleSAML\XML\SerializableElementInterface> $children |
30
|
|
|
*/ |
31
|
|
|
final public function __construct( |
32
|
|
|
array $children = [], |
33
|
|
|
) { |
34
|
|
|
$this->setElements($children); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Test if an object, at the state it's in, would produce an empty XML-element |
40
|
|
|
* |
41
|
|
|
* @return bool |
42
|
|
|
*/ |
43
|
|
|
public function isEmptyElement(): bool |
44
|
|
|
{ |
45
|
|
|
return empty($this->getElements()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Create an instance of this object from its XML representation. |
51
|
|
|
* |
52
|
|
|
* @param \DOMElement $xml |
53
|
|
|
* @return static |
54
|
|
|
* |
55
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
56
|
|
|
* if the qualified name of the supplied element is wrong |
57
|
|
|
*/ |
58
|
|
|
public static function fromXML(DOMElement $xml): static |
59
|
|
|
{ |
60
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
61
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
62
|
|
|
|
63
|
|
|
return new static( |
64
|
|
|
self::getChildElementsFromXML($xml), |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Add this KeyExchangeTokenType to an XML element. |
71
|
|
|
* |
72
|
|
|
* @param \DOMElement|null $parent The element we should append this username token to. |
73
|
|
|
* @return \DOMElement |
74
|
|
|
*/ |
75
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
76
|
|
|
{ |
77
|
|
|
$e = parent::instantiateParentElement($parent); |
78
|
|
|
|
79
|
|
|
foreach ($this->getElements() as $child) { |
80
|
|
|
if (!$child->isEmptyElement()) { |
81
|
|
|
$child->toXML($e); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
return $e; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|