-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathImport.php
More file actions
121 lines (99 loc) · 3.51 KB
/
Copy pathImport.php
File metadata and controls
121 lines (99 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
declare(strict_types=1);
namespace SimpleSAML\XMLSchema\XML;
use DOMElement;
use SimpleSAML\XML\Assert\Assert;
use SimpleSAML\XML\SchemaValidatableElementInterface;
use SimpleSAML\XML\SchemaValidatableElementTrait;
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
use SimpleSAML\XMLSchema\Type\AnyURIValue;
use SimpleSAML\XMLSchema\Type\IDValue;
use function array_last;
use function strval;
/**
* Class representing the import-element.
*
* @package simplesamlphp/xml-common
*/
final class Import extends AbstractAnnotated implements SchemaValidatableElementInterface
{
use SchemaValidatableElementTrait;
public const string LOCALNAME = 'import';
/**
* Import constructor
*
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue|null $namespace
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue|null $schemaLocation
* @param \SimpleSAML\XMLSchema\XML\Annotation|null $annotation
* @param \SimpleSAML\XMLSchema\Type\IDValue|null $id
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
*/
public function __construct(
protected ?AnyURIValue $namespace = null,
protected ?AnyURIValue $schemaLocation = null,
?Annotation $annotation = null,
?IDValue $id = null,
array $namespacedAttributes = [],
) {
parent::__construct($annotation, $id, $namespacedAttributes);
}
/**
* Collect the value of the namespace-property
*
* @return \SimpleSAML\XMLSchema\Type\AnyURIValue|null
*/
public function getNamespace(): ?AnyURIValue
{
return $this->namespace;
}
/**
* Collect the value of the schemaLocation-property
*
* @return \SimpleSAML\XMLSchema\Type\AnyURIValue|null
*/
public function getSchemaLocation(): ?AnyURIValue
{
return $this->schemaLocation;
}
/**
* Add this Import to an XML element.
*
* @param \DOMElement|null $parent The element we should append this import to.
* @return \DOMElement
*/
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = parent::toXML($parent);
if ($this->getNamespace() !== null) {
$e->setAttribute('namespace', strval($this->getNamespace()));
}
if ($this->getSchemaLocation() !== null) {
$e->setAttribute('schemaLocation', strval($this->getSchemaLocation()));
}
return $e;
}
/**
* Create an instance of this object from its XML representation.
*
* @param \DOMElement $xml
* @return static
*
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
* if the qualified name of the supplied element is wrong
*/
public static function fromXML(DOMElement $xml): static
{
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
$annotation = Annotation::getChildrenOfClass($xml);
Assert::maxCount($annotation, 1, TooManyElementsException::class);
return new static(
self::getOptionalAttribute($xml, 'namespace', AnyURIValue::class, null),
self::getOptionalAttribute($xml, 'schemaLocation', AnyURIValue::class, null),
array_last($annotation),
self::getOptionalAttribute($xml, 'id', IDValue::class, null),
self::getAttributesNSFromXML($xml),
);
}
}