|
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\SchemaViolationException; |
|
13
|
|
|
use SimpleSAML\XMLSchema\Exception\TooManyElementsException; |
|
14
|
|
|
use SimpleSAML\XMLSchema\Type\IDValue; |
|
15
|
|
|
use SimpleSAML\XMLSchema\Type\NCNameValue; |
|
16
|
|
|
use SimpleSAML\XMLSchema\Type\QNameValue; |
|
17
|
|
|
use SimpleSAML\XMLSchema\Type\Schema\MaxOccursValue; |
|
18
|
|
|
use SimpleSAML\XMLSchema\Type\Schema\MinOccursValue; |
|
19
|
|
|
use SimpleSAML\XMLSchema\XML\Interface\RedefinableInterface; |
|
20
|
|
|
|
|
21
|
|
|
use function array_merge; |
|
22
|
|
|
use function array_pop; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class representing the group-element. |
|
26
|
|
|
* |
|
27
|
|
|
* @package simplesamlphp/xml-common |
|
28
|
|
|
*/ |
|
29
|
|
|
final class NamedGroup extends AbstractNamedGroup implements |
|
30
|
|
|
RedefinableInterface, |
|
31
|
|
|
SchemaValidatableElementInterface |
|
32
|
|
|
{ |
|
33
|
|
|
use SchemaValidatableElementTrait; |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** @var string */ |
|
37
|
|
|
public const LOCALNAME = 'group'; |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Create an instance of this object from its XML representation. |
|
42
|
|
|
* |
|
43
|
|
|
* @param \DOMElement $xml |
|
44
|
|
|
* @return static |
|
45
|
|
|
* |
|
46
|
|
|
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
|
47
|
|
|
* if the qualified name of the supplied element is wrong |
|
48
|
|
|
*/ |
|
49
|
|
|
public static function fromXML(DOMElement $xml): static |
|
50
|
|
|
{ |
|
51
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
|
52
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
|
53
|
|
|
|
|
54
|
|
|
// Prohibited attributes |
|
55
|
|
|
$ref = self::getOptionalAttribute($xml, 'ref', QNameValue::class, null); |
|
56
|
|
|
Assert::null($ref, SchemaViolationException::class); |
|
57
|
|
|
|
|
58
|
|
|
$minCount = self::getOptionalAttribute($xml, 'minCount', MinOccursValue::class, null); |
|
59
|
|
|
Assert::null($minCount, SchemaViolationException::class); |
|
60
|
|
|
|
|
61
|
|
|
$maxCount = self::getOptionalAttribute($xml, 'maxCount', MaxOccursValue::class, null); |
|
62
|
|
|
Assert::null($maxCount, SchemaViolationException::class); |
|
63
|
|
|
|
|
64
|
|
|
$annotation = Annotation::getChildrenOfClass($xml); |
|
65
|
|
|
Assert::maxCount($annotation, 1, TooManyElementsException::class); |
|
66
|
|
|
|
|
67
|
|
|
$any = All::getChildrenOfClass($xml); |
|
68
|
|
|
Assert::maxCount($any, 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
|
|
|
$particle = array_merge($any, $choice, $sequence); |
|
77
|
|
|
Assert::maxCount($particle, 1, TooManyElementsException::class); |
|
78
|
|
|
|
|
79
|
|
|
return new static( |
|
80
|
|
|
$particle[0], |
|
81
|
|
|
name: self::getAttribute($xml, 'name', NCNameValue::class), |
|
82
|
|
|
annotation: array_pop($annotation), |
|
83
|
|
|
id: self::getOptionalAttribute($xml, 'id', IDValue::class, null), |
|
84
|
|
|
namespacedAttributes: self::getAttributesNSFromXML($xml), |
|
85
|
|
|
); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|