1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\WSSecurity\XML\wsp; |
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\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; |
13
|
|
|
use SimpleSAML\XML\XsNamespace as NS; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class representing a wsp:AppliesTo element. |
17
|
|
|
* |
18
|
|
|
* @package simplesamlphp/ws-security |
19
|
|
|
*/ |
20
|
|
|
final class AppliesTo extends AbstractWspElement implements SchemaValidatableElementInterface |
21
|
|
|
{ |
22
|
|
|
use ExtendableAttributesTrait; |
23
|
|
|
use ExtendableElementTrait; |
|
|
|
|
24
|
|
|
use SchemaValidatableElementTrait; |
|
|
|
|
25
|
|
|
|
26
|
|
|
/** The namespace-attribute for the xs:any element */ |
27
|
|
|
public const XS_ANY_ELT_NAMESPACE = NS::ANY; |
28
|
|
|
|
29
|
|
|
/** The namespace-attribute for the xs:anyAttribute element */ |
30
|
|
|
public const XS_ANY_ATTR_NAMESPACE = NS::ANY; |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Initialize a wsp:AppliesTo |
35
|
|
|
* |
36
|
|
|
* @param array<\SimpleSAML\XML\SerializableElementInterface> $children |
37
|
|
|
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes |
38
|
|
|
*/ |
39
|
|
|
public function __construct(array $children = [], 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->elements) && empty($this->namespacedAttributes); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/* |
58
|
|
|
* Convert XML into an wsp:AppliesTo element |
59
|
|
|
* |
60
|
|
|
* @param \DOMElement $xml The XML element we should load |
61
|
|
|
* @return static |
62
|
|
|
* |
63
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
64
|
|
|
* If the qualified name of the supplied element is wrong |
65
|
|
|
*/ |
66
|
|
|
public static function fromXML(DOMElement $xml): static |
67
|
|
|
{ |
68
|
|
|
Assert::same($xml->localName, 'AppliesTo', InvalidDOMElementException::class); |
69
|
|
|
Assert::same($xml->namespaceURI, AppliesTo::NS, InvalidDOMElementException::class); |
70
|
|
|
|
71
|
|
|
return new static( |
72
|
|
|
self::getChildElementsFromXML($xml), |
73
|
|
|
self::getAttributesNSFromXML($xml), |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Convert this wsp:AppliesTo to XML. |
80
|
|
|
* |
81
|
|
|
* @param \DOMElement|null $parent The element we should add this wsp:AppliesTo to. |
82
|
|
|
* @return \DOMElement This wsp:AppliesTo element. |
83
|
|
|
*/ |
84
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
85
|
|
|
{ |
86
|
|
|
$e = $this->instantiateParentElement($parent); |
87
|
|
|
|
88
|
|
|
foreach ($this->getAttributesNS() as $attr) { |
89
|
|
|
$attr->toXML($e); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** @psalm-var \SimpleSAML\XML\SerializableElementInterface $child */ |
93
|
|
|
foreach ($this->getElements() as $child) { |
94
|
|
|
if (!$child->isEmptyElement()) { |
95
|
|
|
$child->toXML($e); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
return $e; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|