|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSchema\XML\xs; |
|
6
|
|
|
|
|
7
|
|
|
use DOMElement; |
|
8
|
|
|
use SimpleSAML\XML\{ExtendableAttributesTrait, ExtendableElementTrait}; |
|
9
|
|
|
use SimpleSAML\XMLSchema\XML\xs\NamespaceEnum; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Abstract class to be implemented by all the classes that use the xs:anyType complex type |
|
13
|
|
|
* |
|
14
|
|
|
* @package simplesamlphp/xml-common |
|
15
|
|
|
*/ |
|
16
|
|
|
abstract class AbstractAnyType extends AbstractXsElement |
|
17
|
|
|
{ |
|
18
|
|
|
use ExtendableAttributesTrait; |
|
|
|
|
|
|
19
|
|
|
use ExtendableElementTrait; |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
/** The namespace-attribute for the xs:any element */ |
|
22
|
|
|
public const XS_ANY_ELT_NAMESPACE = NamespaceEnum::Any; |
|
23
|
|
|
|
|
24
|
|
|
/** The namespace-attribute for the xs:anyAttribute element */ |
|
25
|
|
|
public const XS_ANY_ATTR_NAMESPACE = NamespaceEnum::Any; |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* AbstractAnyType constructor |
|
30
|
|
|
* |
|
31
|
|
|
* @param array<\SimpleSAML\XML\SerializableElementInterface> $elements |
|
32
|
|
|
* @param array<\SimpleSAML\XML\Attribute> $attributes |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct( |
|
35
|
|
|
array $elements = [], |
|
36
|
|
|
array $attributes = [], |
|
37
|
|
|
) { |
|
38
|
|
|
$this->setElements($elements); |
|
39
|
|
|
$this->setAttributesNS($attributes); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Test if an object, at the state it's in, would produce an empty XML-element |
|
45
|
|
|
* |
|
46
|
|
|
* @return bool |
|
47
|
|
|
*/ |
|
48
|
|
|
public function isEmptyElement(): bool |
|
49
|
|
|
{ |
|
50
|
|
|
return empty($this->getAttributesNS()) |
|
51
|
|
|
&& empty($this->getElements()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Add this AnyType to an XML element. |
|
57
|
|
|
* |
|
58
|
|
|
* @param \DOMElement|null $parent The element we should append this anyType to. |
|
59
|
|
|
* @return \DOMElement |
|
60
|
|
|
*/ |
|
61
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
|
62
|
|
|
{ |
|
63
|
|
|
$e = parent::instantiateParentElement($parent); |
|
64
|
|
|
|
|
65
|
|
|
foreach ($this->getAttributesNS() as $attr) { |
|
66
|
|
|
$attr->toXML($e); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
foreach ($this->getElements() as $elt) { |
|
70
|
|
|
$elt->toXML($e); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $e; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|