1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSchema\XML\xs; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\XML\Assert\Assert; |
9
|
|
|
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; |
10
|
|
|
use SimpleSAML\XMLSchema\Exception\{InvalidDOMElementException, TooManyElementsException}; |
11
|
|
|
use SimpleSAML\XMLSchema\Type\Builtin\{BooleanValue, IDValue}; |
12
|
|
|
|
13
|
|
|
use function array_merge; |
14
|
|
|
use function strval; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class representing the complexContent-type. |
18
|
|
|
* |
19
|
|
|
* @package simplesamlphp/xml-common |
20
|
|
|
*/ |
21
|
|
|
final class ComplexContent extends AbstractAnnotated implements SchemaValidatableElementInterface |
22
|
|
|
{ |
23
|
|
|
use SchemaValidatableElementTrait; |
|
|
|
|
24
|
|
|
|
25
|
|
|
/** @var string */ |
26
|
|
|
public const LOCALNAME = 'complexContent'; |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* ComplexContent constructor |
31
|
|
|
* |
32
|
|
|
* @param \SimpleSAML\XMLSchema\XML\xs\ComplexRestriction|\SimpleSAML\XMLSchema\XML\xs\Extension $content |
33
|
|
|
* @param \SimpleSAML\XMLSchema\Type\Builtin\BooleanValue|null $mixed |
34
|
|
|
* @param \SimpleSAML\XMLSchema\XML\xs\Annotation|null $annotation |
35
|
|
|
* @param \SimpleSAML\XMLSchema\Type\Builtin\IDValue|null $id |
36
|
|
|
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes |
37
|
|
|
*/ |
38
|
|
|
public function __construct( |
39
|
|
|
protected ComplexRestriction|Extension $content, |
40
|
|
|
protected ?BooleanValue $mixed = null, |
41
|
|
|
?Annotation $annotation = null, |
42
|
|
|
?IDValue $id = null, |
43
|
|
|
array $namespacedAttributes = [], |
44
|
|
|
) { |
45
|
|
|
parent::__construct($annotation, $id, $namespacedAttributes); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Collect the value of the content-property |
51
|
|
|
* |
52
|
|
|
* @return \SimpleSAML\XMLSchema\XML\xs\ComplexRestriction|\SimpleSAML\XMLSchema\XML\xs\Extension |
53
|
|
|
*/ |
54
|
|
|
public function getContent(): ComplexRestriction|Extension |
55
|
|
|
{ |
56
|
|
|
return $this->content; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Collect the value of the mixed-property |
62
|
|
|
* |
63
|
|
|
* @return \SimpleSAML\XMLSchema\Type\Builtin\BooleanValue|null |
64
|
|
|
*/ |
65
|
|
|
public function getMixed(): ?BooleanValue |
66
|
|
|
{ |
67
|
|
|
return $this->mixed; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Test if an object, at the state it's in, would produce an empty XML-element |
73
|
|
|
* |
74
|
|
|
* @return bool |
75
|
|
|
*/ |
76
|
|
|
public function isEmptyElement(): bool |
77
|
|
|
{ |
78
|
|
|
return false; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Add this ComplexContent to an XML element. |
84
|
|
|
* |
85
|
|
|
* @param \DOMElement|null $parent The element we should append this ComplexContent to. |
86
|
|
|
* @return \DOMElement |
87
|
|
|
*/ |
88
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
89
|
|
|
{ |
90
|
|
|
$e = parent::toXML($parent); |
91
|
|
|
|
92
|
|
|
if ($this->getMixed() !== null) { |
93
|
|
|
$e->setAttribute('mixed', strval($this->getMixed())); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$this->getContent()->toXML($e); |
97
|
|
|
|
98
|
|
|
return $e; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Create an instance of this object from its XML representation. |
104
|
|
|
* |
105
|
|
|
* @param \DOMElement $xml |
106
|
|
|
* @return static |
107
|
|
|
* |
108
|
|
|
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
109
|
|
|
* if the qualified name of the supplied element is wrong |
110
|
|
|
*/ |
111
|
|
|
public static function fromXML(DOMElement $xml): static |
112
|
|
|
{ |
113
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
114
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
115
|
|
|
|
116
|
|
|
$annotation = Annotation::getChildrenOfClass($xml); |
117
|
|
|
Assert::maxCount($annotation, 1, TooManyElementsException::class); |
118
|
|
|
|
119
|
|
|
$complexRestriction = ComplexRestriction::getChildrenOfClass($xml); |
120
|
|
|
Assert::maxCount($complexRestriction, 1, TooManyElementsException::class); |
121
|
|
|
|
122
|
|
|
$extension = Extension::getChildrenOfClass($xml); |
123
|
|
|
Assert::maxCount($extension, 1, TooManyElementsException::class); |
124
|
|
|
|
125
|
|
|
$content = array_merge($complexRestriction, $extension); |
126
|
|
|
Assert::maxCount($content, 1, TooManyElementsException::class); |
127
|
|
|
|
128
|
|
|
return new static( |
129
|
|
|
$content[0], |
130
|
|
|
self::getOptionalAttribute($xml, 'mixed', BooleanValue::class, null), |
131
|
|
|
array_pop($annotation), |
132
|
|
|
self::getOptionalAttribute($xml, 'id', IDValue::class, null), |
133
|
|
|
self::getAttributesNSFromXML($xml), |
134
|
|
|
); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|