1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSchema\XML; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\XML\Assert\Assert; |
9
|
|
|
use SimpleSAML\XML\SchemaValidatableElementInterface; |
10
|
|
|
use SimpleSAML\XML\SchemaValidatableElementTrait; |
11
|
|
|
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException; |
12
|
|
|
use SimpleSAML\XMLSchema\Exception\TooManyElementsException; |
13
|
|
|
use SimpleSAML\XMLSchema\Type\BooleanValue; |
14
|
|
|
use SimpleSAML\XMLSchema\Type\IDValue; |
15
|
|
|
use SimpleSAML\XMLSchema\Type\NCNameValue; |
16
|
|
|
use SimpleSAML\XMLSchema\Type\Schema\DerivationSetValue; |
17
|
|
|
use SimpleSAML\XMLSchema\XML\Interface\RedefinableInterface; |
18
|
|
|
|
19
|
|
|
use function array_merge; |
20
|
|
|
use function array_pop; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class representing the xs:complexType element. |
24
|
|
|
* |
25
|
|
|
* @package simplesamlphp/xml-common |
26
|
|
|
*/ |
27
|
|
|
final class TopLevelComplexType extends AbstractTopLevelComplexType implements |
28
|
|
|
RedefinableInterface, |
29
|
|
|
SchemaValidatableElementInterface |
30
|
|
|
{ |
31
|
|
|
use SchemaValidatableElementTrait; |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
/** @var string */ |
35
|
|
|
public const LOCALNAME = 'complexType'; |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Create an instance of this object from its XML representation. |
40
|
|
|
* |
41
|
|
|
* @param \DOMElement $xml |
42
|
|
|
* @return static |
43
|
|
|
* |
44
|
|
|
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
45
|
|
|
* if the qualified name of the supplied element is wrong |
46
|
|
|
*/ |
47
|
|
|
public static function fromXML(DOMElement $xml): static |
48
|
|
|
{ |
49
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
50
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
51
|
|
|
|
52
|
|
|
$annotation = Annotation::getChildrenOfClass($xml); |
53
|
|
|
Assert::maxCount($annotation, 1, TooManyElementsException::class); |
54
|
|
|
|
55
|
|
|
$simpleContent = SimpleContent::getChildrenOfClass($xml); |
56
|
|
|
Assert::maxCount($simpleContent, 1, TooManyElementsException::class); |
57
|
|
|
|
58
|
|
|
$complexContent = ComplexContent::getChildrenOfClass($xml); |
59
|
|
|
Assert::maxCount($complexContent, 1, TooManyElementsException::class); |
60
|
|
|
|
61
|
|
|
$content = array_merge($simpleContent, $complexContent); |
62
|
|
|
Assert::maxCount($content, 1, TooManyElementsException::class); |
63
|
|
|
|
64
|
|
|
$referencedGroup = ReferencedGroup::getChildrenOfClass($xml); |
65
|
|
|
Assert::maxCount($referencedGroup, 1, TooManyElementsException::class); |
66
|
|
|
|
67
|
|
|
$all = All::getChildrenOfClass($xml); |
68
|
|
|
Assert::maxCount($all, 1, TooManyElementsException::class); |
69
|
|
|
|
70
|
|
|
$choice = Choice::getChildrenOfClass($xml); |
71
|
|
|
Assert::maxCount($choice, 1, TooManyElementsException::class); |
72
|
|
|
|
73
|
|
|
$sequence = Sequence::getChildrenOfClass($xml); |
74
|
|
|
Assert::maxCount($sequence, 1, TooManyElementsException::class); |
75
|
|
|
|
76
|
|
|
$particles = array_merge($referencedGroup, $all, $choice, $sequence); |
77
|
|
|
Assert::maxCount($particles, 1, TooManyElementsException::class); |
78
|
|
|
|
79
|
|
|
$localAttribute = LocalAttribute::getChildrenOfClass($xml); |
80
|
|
|
$referencedAttributeGroup = ReferencedAttributeGroup::getChildrenOfClass($xml); |
81
|
|
|
$attributes = array_merge($localAttribute, $referencedAttributeGroup); |
82
|
|
|
|
83
|
|
|
$anyAttribute = AnyAttribute::getChildrenOfClass($xml); |
84
|
|
|
Assert::maxCount($anyAttribute, 1, TooManyElementsException::class); |
85
|
|
|
|
86
|
|
|
return new static( |
87
|
|
|
self::getAttribute($xml, 'name', NCNameValue::class), |
88
|
|
|
self::getOptionalAttribute($xml, 'mixed', BooleanValue::class, null), |
89
|
|
|
self::getOptionalAttribute($xml, 'abstract', BooleanValue::class, null), |
90
|
|
|
self::getOptionalAttribute($xml, 'final', DerivationSetValue::class, null), |
91
|
|
|
self::getOptionalAttribute($xml, 'block', DerivationSetValue::class, null), |
92
|
|
|
array_pop($content), |
93
|
|
|
array_pop($particles), |
94
|
|
|
$attributes, |
95
|
|
|
array_pop($anyAttribute), |
96
|
|
|
array_pop($annotation), |
97
|
|
|
self::getOptionalAttribute($xml, 'id', IDValue::class, null), |
98
|
|
|
self::getAttributesNSFromXML($xml), |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|