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\XMLSchema\Exception\InvalidDOMElementException; |
10
|
|
|
use SimpleSAML\XMLSchema\Exception\SchemaViolationException; |
11
|
|
|
use SimpleSAML\XMLSchema\Exception\TooManyElementsException; |
12
|
|
|
use SimpleSAML\XMLSchema\Type\IDValue; |
13
|
|
|
use SimpleSAML\XMLSchema\Type\NCNameValue; |
14
|
|
|
use SimpleSAML\XMLSchema\Type\QNameValue; |
15
|
|
|
|
16
|
|
|
use function array_merge; |
17
|
|
|
use function array_pop; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class representing the sequence-element. |
21
|
|
|
* |
22
|
|
|
* @package simplesamlphp/xml-common |
23
|
|
|
*/ |
24
|
|
|
final class SimpleSequence extends AbstractSimpleExplicitGroup |
25
|
|
|
{ |
26
|
|
|
/** @var string */ |
27
|
|
|
public const LOCALNAME = 'sequence'; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Create an instance of this object from its XML representation. |
32
|
|
|
* |
33
|
|
|
* @param \DOMElement $xml |
34
|
|
|
* @return static |
35
|
|
|
* |
36
|
|
|
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
37
|
|
|
* if the qualified name of the supplied element is wrong |
38
|
|
|
*/ |
39
|
|
|
public static function fromXML(DOMElement $xml): static |
40
|
|
|
{ |
41
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
42
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
43
|
|
|
|
44
|
|
|
// Prohibited attributes |
45
|
|
|
$name = self::getOptionalAttribute($xml, 'name', NCNameValue::class, null); |
46
|
|
|
Assert::null($name, SchemaViolationException::class); |
47
|
|
|
|
48
|
|
|
$ref = self::getOptionalAttribute($xml, 'ref', QNameValue::class, null); |
49
|
|
|
Assert::null($ref, SchemaViolationException::class); |
50
|
|
|
|
51
|
|
|
$name = self::getOptionalAttribute($xml, 'name', NCNameValue::class, null); |
52
|
|
|
Assert::null($name, SchemaViolationException::class); |
53
|
|
|
|
54
|
|
|
$ref = self::getOptionalAttribute($xml, 'ref', QNameValue::class, null); |
55
|
|
|
Assert::null($ref, SchemaViolationException::class); |
56
|
|
|
|
57
|
|
|
// Start here |
58
|
|
|
$annotation = Annotation::getChildrenOfClass($xml); |
59
|
|
|
Assert::maxCount($annotation, 1, TooManyElementsException::class); |
60
|
|
|
|
61
|
|
|
$any = Any::getChildrenOfClass($xml); |
62
|
|
|
$choice = Choice::getChildrenOfClass($xml); |
63
|
|
|
$localElement = LocalElement::getChildrenOfClass($xml); |
64
|
|
|
$referencedGroup = ReferencedGroup::getChildrenOfClass($xml); |
65
|
|
|
$sequence = Sequence::getChildrenOfClass($xml); |
66
|
|
|
|
67
|
|
|
$particles = array_merge($any, $choice, $localElement, $referencedGroup, $sequence); |
68
|
|
|
|
69
|
|
|
return new static( |
70
|
|
|
nestedParticles: $particles, |
71
|
|
|
annotation: array_pop($annotation), |
72
|
|
|
id: self::getOptionalAttribute($xml, 'id', IDValue::class, null), |
73
|
|
|
namespacedAttributes: self::getAttributesNSFromXML($xml), |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|