|
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\TooManyElementsException; |
|
11
|
|
|
use SimpleSAML\XMLSchema\Type\IDValue; |
|
12
|
|
|
use SimpleSAML\XMLSchema\Type\QNameValue; |
|
13
|
|
|
|
|
14
|
|
|
use function array_merge; |
|
15
|
|
|
use function array_pop; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class representing the simple version of the xs:extension. |
|
19
|
|
|
* |
|
20
|
|
|
* @package simplesamlphp/xml-common |
|
21
|
|
|
*/ |
|
22
|
|
|
final class SimpleExtension extends AbstractSimpleExtensionType |
|
23
|
|
|
{ |
|
24
|
|
|
/** @var string */ |
|
25
|
|
|
public const LOCALNAME = 'extension'; |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Create an instance of this object from its XML representation. |
|
30
|
|
|
* |
|
31
|
|
|
* @param \DOMElement $xml |
|
32
|
|
|
* @return static |
|
33
|
|
|
* |
|
34
|
|
|
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
|
35
|
|
|
* if the qualified name of the supplied element is wrong |
|
36
|
|
|
*/ |
|
37
|
|
|
public static function fromXML(DOMElement $xml): static |
|
38
|
|
|
{ |
|
39
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
|
40
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
|
41
|
|
|
|
|
42
|
|
|
$annotation = Annotation::getChildrenOfClass($xml); |
|
43
|
|
|
Assert::maxCount($annotation, 1, TooManyElementsException::class); |
|
44
|
|
|
|
|
45
|
|
|
$localAttribute = LocalAttribute::getChildrenOfClass($xml); |
|
46
|
|
|
$attributeGroup = ReferencedAttributeGroup::getChildrenOfClass($xml); |
|
47
|
|
|
$attributes = array_merge($localAttribute, $attributeGroup); |
|
48
|
|
|
|
|
49
|
|
|
$anyAttribute = AnyAttribute::getChildrenOfClass($xml); |
|
50
|
|
|
Assert::maxCount($anyAttribute, 1, TooManyElementsException::class); |
|
51
|
|
|
|
|
52
|
|
|
return new static( |
|
53
|
|
|
self::getAttribute($xml, 'base', QNameValue::class), |
|
54
|
|
|
$attributes, |
|
55
|
|
|
array_pop($anyAttribute), |
|
56
|
|
|
array_pop($annotation), |
|
57
|
|
|
self::getOptionalAttribute($xml, 'id', IDValue::class, null), |
|
58
|
|
|
self::getAttributesNSFromXML($xml), |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|