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