1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\WSSecurity\XML\sp_200702; |
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\ExtendableElementTrait; |
13
|
|
|
use SimpleSAML\XML\XsNamespace as NS; |
14
|
|
|
|
15
|
|
|
use function sprintf; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class representing WS security policy SetElementsType. |
19
|
|
|
* |
20
|
|
|
* @package simplesamlphp/ws-security |
21
|
|
|
*/ |
22
|
|
|
abstract class AbstractSerElementsType extends AbstractSpElement |
23
|
|
|
{ |
24
|
|
|
use ExtendableAttributesTrait; |
25
|
|
|
use ExtendableElementTrait; |
|
|
|
|
26
|
|
|
|
27
|
|
|
/** The namespace-attribute for the xs:any element */ |
28
|
|
|
public const XS_ANY_ELT_NAMESPACE = NS::OTHER; |
29
|
|
|
|
30
|
|
|
/** The namespace-attribute for the xs:anyAttribute element */ |
31
|
|
|
public const XS_ANY_ATTR_NAMESPACE = NS::ANY; |
32
|
|
|
|
33
|
|
|
/** The exclusions for the xs:anyAttribute element */ |
34
|
|
|
public const XS_ANY_ATTR_EXCLUSIONS = [ |
35
|
|
|
['http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702', 'XPathVersion'], |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* AbstractSerElementsType constructor. |
41
|
|
|
* |
42
|
|
|
* @param list<\SimpleSAML\WSSecurity\XML\sp_200702\XPath> $xpath |
|
|
|
|
43
|
|
|
* @param string|null $xpathVersion |
44
|
|
|
* @param array<\SimpleSAML\XML\SerializableElementInterface> $elts |
45
|
|
|
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes |
46
|
|
|
*/ |
47
|
|
|
final public function __construct( |
48
|
|
|
protected array $xpath, |
49
|
|
|
protected ?string $xpathVersion = null, |
50
|
|
|
array $elts = [], |
51
|
|
|
array $namespacedAttributes = [], |
52
|
|
|
) { |
53
|
|
|
Assert::minCount($xpath, 1, SchemaViolationException::class); |
|
|
|
|
54
|
|
|
Assert::nullOrValidURI($xpathVersion); |
|
|
|
|
55
|
|
|
|
56
|
|
|
$this->setElements($elts); |
57
|
|
|
$this->setAttributesNS($namespacedAttributes); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Collect the value of the XPath property. |
63
|
|
|
* |
64
|
|
|
* @return list<\SimpleSAML\WSSecurity\XML\sp_200702\XPath> |
65
|
|
|
*/ |
66
|
|
|
public function getXPath(): array |
67
|
|
|
{ |
68
|
|
|
return $this->xpath; |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Collect the value of the XPathVersion property. |
74
|
|
|
* |
75
|
|
|
* @return string|null |
76
|
|
|
*/ |
77
|
|
|
public function getXPathVersion(): ?string |
78
|
|
|
{ |
79
|
|
|
return $this->xpathVersion; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Initialize an SerElementsType. |
85
|
|
|
* |
86
|
|
|
* Note: this method cannot be used when extending this class, if the constructor has a different signature. |
87
|
|
|
* |
88
|
|
|
* @param \DOMElement $xml The XML element we should load. |
89
|
|
|
* @return static |
90
|
|
|
* |
91
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
92
|
|
|
* if the qualified name of the supplied element is wrong |
93
|
|
|
*/ |
94
|
|
|
public static function fromXML(DOMElement $xml): static |
95
|
|
|
{ |
96
|
|
|
$qualifiedName = static::getClassName(static::class); |
97
|
|
|
Assert::eq( |
|
|
|
|
98
|
|
|
$xml->localName, |
99
|
|
|
$qualifiedName, |
100
|
|
|
sprintf('Unexpected name for SerElementsType: %s. Expected: %s.', $xml->localName, $qualifiedName), |
101
|
|
|
InvalidDOMElementException::class, |
102
|
|
|
); |
103
|
|
|
|
104
|
|
|
return new static( |
105
|
|
|
XPath::getChildrenOfClass($xml), |
106
|
|
|
$xml->hasAttributeNS(self::NS, 'XPathVersion') ? $xml->getAttributeNS(self::NS, 'XPathVersion') : null, |
107
|
|
|
self::getChildElementsFromXML($xml), |
108
|
|
|
self::getAttributesNSFromXML($xml), |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Convert this element to XML. |
115
|
|
|
* |
116
|
|
|
* @param \DOMElement|null $parent The element we should append this element to. |
117
|
|
|
* @return \DOMElement |
118
|
|
|
*/ |
119
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
120
|
|
|
{ |
121
|
|
|
$e = $this->instantiateParentElement($parent); |
122
|
|
|
|
123
|
|
|
if ($this->getXPathVersion() !== null) { |
124
|
|
|
$e->setAttributeNS(self::NS, 'sp:XPathVersion', $this->getXPathVersion()); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
foreach ($this->getXPath() as $xpath) { |
128
|
|
|
$xpath->toXML($e); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
foreach ($this->getElements() as $elt) { |
132
|
|
|
/** @psalm-var \SimpleSAML\XML\SerializableElementInterface $elt */ |
133
|
|
|
$elt->toXML($e); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
foreach ($this->getAttributesNS() as $attr) { |
137
|
|
|
$attr->toXML($e); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
return $e; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|