|
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\{IDValue, NCNameValue}; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class representing the key-element. |
|
15
|
|
|
* |
|
16
|
|
|
* @package simplesamlphp/xml-common |
|
17
|
|
|
*/ |
|
18
|
|
|
final class Key extends AbstractKeybase implements IdentityConstraintInterface, SchemaValidatableElementInterface |
|
19
|
|
|
{ |
|
20
|
|
|
use SchemaValidatableElementTrait; |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
/** @var string */ |
|
23
|
|
|
public const LOCALNAME = 'key'; |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Key constructor |
|
28
|
|
|
* |
|
29
|
|
|
* @param \SimpleSAML\XMLSchema\Type\Builtin\NCNameValue $name |
|
30
|
|
|
* @param \SimpleSAML\XMLSchema\XML\xs\Selector $selector |
|
31
|
|
|
* @param array<\SimpleSAML\XMLSchema\XML\xs\Field> $field |
|
32
|
|
|
* @param \SimpleSAML\XMLSchema\XML\xs\Annotation|null $annotation |
|
33
|
|
|
* @param \SimpleSAML\XMLSchema\Type\Builtin\IDValue|null $id |
|
34
|
|
|
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct( |
|
37
|
|
|
NCNameValue $name, |
|
38
|
|
|
Selector $selector, |
|
39
|
|
|
array $field = [], |
|
40
|
|
|
?Annotation $annotation = null, |
|
41
|
|
|
?IDValue $id = null, |
|
42
|
|
|
array $namespacedAttributes = [], |
|
43
|
|
|
) { |
|
44
|
|
|
parent::__construct($name, $selector, $field, $annotation, $id, $namespacedAttributes); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Create an instance of this object from its XML representation. |
|
50
|
|
|
* |
|
51
|
|
|
* @param \DOMElement $xml |
|
52
|
|
|
* @return static |
|
53
|
|
|
* |
|
54
|
|
|
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
|
55
|
|
|
* if the qualified name of the supplied element is wrong |
|
56
|
|
|
*/ |
|
57
|
|
|
public static function fromXML(DOMElement $xml): static |
|
58
|
|
|
{ |
|
59
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
|
60
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
|
61
|
|
|
|
|
62
|
|
|
$annotation = Annotation::getChildrenOfClass($xml); |
|
63
|
|
|
Assert::maxCount($annotation, 1, TooManyElementsException::class); |
|
64
|
|
|
|
|
65
|
|
|
$selector = Selector::getChildrenOfClass($xml); |
|
66
|
|
|
Assert::maxCount($selector, 1, TooManyElementsException::class); |
|
67
|
|
|
|
|
68
|
|
|
$field = Field::getChildrenOfClass($xml); |
|
69
|
|
|
|
|
70
|
|
|
return new static( |
|
71
|
|
|
self::getAttribute($xml, 'name', NCNameValue::class), |
|
72
|
|
|
$selector[0], |
|
73
|
|
|
$field, |
|
74
|
|
|
array_pop($annotation), |
|
75
|
|
|
self::getOptionalAttribute($xml, 'id', IDValue::class, null), |
|
76
|
|
|
self::getAttributesNSFromXML($xml), |
|
77
|
|
|
); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|