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