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