1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\XML\xenc11; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\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 representing xenc11:Parameters |
16
|
|
|
* |
17
|
|
|
* @package simplesamlphp/xml-security |
18
|
|
|
*/ |
19
|
|
|
final class Parameters extends AbstractXenc11Element |
20
|
|
|
{ |
21
|
|
|
use ExtendableAttributesTrait; |
|
|
|
|
22
|
|
|
use ExtendableElementTrait; |
23
|
|
|
|
24
|
|
|
/** The namespace-attribute for the xs:any element */ |
25
|
|
|
public const XS_ANY_ELT_NAMESPACE = NS::ANY; |
26
|
|
|
|
27
|
|
|
/** The namespace-attribute for the xs:anyAttribute element */ |
28
|
|
|
public const XS_ANY_ATTR_NAMESPACE = NS::ANY; |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Initialize a Parameters element. |
33
|
|
|
* |
34
|
|
|
* @param array<\SimpleSAML\XML\SerializableElementInterface> $elements |
35
|
|
|
* @param array<\SimpleSAML\XML\Attribute> $attributes |
36
|
|
|
*/ |
37
|
|
|
public function __construct(array $elements = [], array $attributes = []) |
38
|
|
|
{ |
39
|
|
|
$this->setElements($elements); |
40
|
|
|
$this->setAttributesNS($attributes); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Test if an object, at the state it's in, would produce an empty XML-element |
47
|
|
|
* |
48
|
|
|
* @return bool |
49
|
|
|
*/ |
50
|
|
|
public function isEmptyElement(): bool |
51
|
|
|
{ |
52
|
|
|
return empty($this->getAttributesNS()) |
53
|
|
|
&& empty($this->getElements()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Convert XML into a Parameters 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, 'Parameters', InvalidDOMElementException::class); |
69
|
|
|
Assert::same($xml->namespaceURI, Parameters::NS, InvalidDOMElementException::class); |
70
|
|
|
|
71
|
|
|
return new static( |
72
|
|
|
self::getChildElementsFromXML($xml), |
73
|
|
|
self::getAttributesNSFromXML($xml), |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Convert this Parameters element to XML. |
80
|
|
|
* |
81
|
|
|
* @param \DOMElement|null $parent The element we should append this Parameters to. |
82
|
|
|
* @return \DOMElement |
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
|
|
|
foreach ($this->getElements() as $element) { |
93
|
|
|
/** @psalm-var \SimpleSAML\XML\SerializableElementInterface $element */ |
94
|
|
|
$element->toXML($e); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $e; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|