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, SchemaViolationException, TooManyElementsException}; |
11
|
|
|
use SimpleSAML\XMLSchema\Type\Builtin\{BooleanValue, IDValue, NCNameValue, QNameValue, StringValue}; |
12
|
|
|
use SimpleSAML\XMLSchema\Type\{BlockSetValue, DerivationSetValue, FormChoiceValue, MaxOccursValue, MinOccursValue}; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class representing the topLevelElement-type. |
16
|
|
|
* |
17
|
|
|
* @package simplesamlphp/xml-common |
18
|
|
|
*/ |
19
|
|
|
final class TopLevelElement extends AbstractTopLevelElement implements SchemaValidatableElementInterface |
20
|
|
|
{ |
21
|
|
|
use SchemaValidatableElementTrait; |
|
|
|
|
22
|
|
|
|
23
|
|
|
/** @var string */ |
24
|
|
|
public const LOCALNAME = 'element'; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Create an instance of this object from its XML representation. |
29
|
|
|
* |
30
|
|
|
* @param \DOMElement $xml |
31
|
|
|
* @return static |
32
|
|
|
* |
33
|
|
|
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
34
|
|
|
* if the qualified name of the supplied element is wrong |
35
|
|
|
*/ |
36
|
|
|
public static function fromXML(DOMElement $xml): static |
37
|
|
|
{ |
38
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
39
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
40
|
|
|
|
41
|
|
|
// Prohibited attributes |
42
|
|
|
$ref = self::getOptionalAttribute($xml, 'ref', QNameValue::class, null); |
43
|
|
|
Assert::null($ref, SchemaViolationException::class); |
44
|
|
|
|
45
|
|
|
$form = self::getOptionalAttribute($xml, 'form', FormChoiceValue::class, null); |
46
|
|
|
Assert::null($form, SchemaViolationException::class); |
47
|
|
|
|
48
|
|
|
$minCount = self::getOptionalAttribute($xml, 'minCount', MinOccursValue::class, null); |
49
|
|
|
Assert::null($minCount, SchemaViolationException::class); |
50
|
|
|
|
51
|
|
|
$maxCount = self::getOptionalAttribute($xml, 'maxCount', MaxOccursValue::class, null); |
52
|
|
|
Assert::null($maxCount, SchemaViolationException::class); |
53
|
|
|
|
54
|
|
|
// The annotation |
55
|
|
|
$annotation = Annotation::getChildrenOfClass($xml); |
56
|
|
|
Assert::maxCount($annotation, 1, TooManyElementsException::class); |
57
|
|
|
|
58
|
|
|
// The local type |
59
|
|
|
$localSimpleType = LocalSimpleType::getChildrenOfClass($xml); |
60
|
|
|
Assert::maxCount($localSimpleType, 1, TooManyElementsException::class); |
61
|
|
|
|
62
|
|
|
$localComplexType = LocalComplexType::getChildrenOfClass($xml); |
63
|
|
|
Assert::maxCount($localComplexType, 1, TooManyElementsException::class); |
64
|
|
|
|
65
|
|
|
$localType = array_merge($localSimpleType, $localComplexType); |
66
|
|
|
Assert::maxCount($localType, 1, TooManyElementsException::class); |
67
|
|
|
|
68
|
|
|
// The identity constraint |
69
|
|
|
$key = Key::getChildrenOfClass($xml); |
70
|
|
|
$keyref = Keyref::getChildrenOfClass($xml); |
71
|
|
|
$unique = Unique::getChildrenOfClass($xml); |
72
|
|
|
$identityConstraint = array_merge($key, $keyref, $unique); |
73
|
|
|
|
74
|
|
|
return new static( |
75
|
|
|
self::getAttribute($xml, 'name', NCNameValue::class), |
76
|
|
|
array_pop($localType), |
77
|
|
|
$identityConstraint, |
78
|
|
|
self::getOptionalAttribute($xml, 'type', QNameValue::class, null), |
79
|
|
|
self::getOptionalAttribute($xml, 'substitutionGroup', QNameValue::class, null), |
80
|
|
|
self::getOptionalAttribute($xml, 'default', StringValue::class, null), |
81
|
|
|
self::getOptionalAttribute($xml, 'fixed', StringValue::class, null), |
82
|
|
|
self::getOptionalAttribute($xml, 'nillable', BooleanValue::class, null), |
83
|
|
|
self::getOptionalAttribute($xml, 'abstract', BooleanValue::class, null), |
84
|
|
|
self::getOptionalAttribute($xml, 'final', DerivationSetValue::class, null), |
85
|
|
|
self::getOptionalAttribute($xml, 'block', BlockSetValue::class, null), |
86
|
|
|
array_pop($annotation), |
87
|
|
|
self::getOptionalAttribute($xml, 'id', IDValue::class, null), |
88
|
|
|
self::getAttributesNSFromXML($xml), |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|