1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSchema\XML; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\XMLSchema\Type\{IDValue, NCNameValue, QNameValue}; |
9
|
|
|
use SimpleSAML\XMLSchema\XML\Trait\{AttrDeclsTrait, DefRefTrait}; |
10
|
|
|
|
11
|
|
|
use function strval; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Abstract class representing the attributeGroup-type. |
15
|
|
|
* |
16
|
|
|
* @package simplesamlphp/xml-common |
17
|
|
|
*/ |
18
|
|
|
abstract class AbstractAttributeGroup extends AbstractAnnotated |
19
|
|
|
{ |
20
|
|
|
use AttrDeclsTrait; |
21
|
|
|
use DefRefTrait; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* AttributeGroup constructor |
25
|
|
|
* |
26
|
|
|
* @param ( |
27
|
|
|
* \SimpleSAML\XMLSchema\XML\LocalAttribute| |
28
|
|
|
* \SimpleSAML\XMLSchema\XML\ReferencedAttributeGroup |
29
|
|
|
* )[] $attributes |
30
|
|
|
* @param \SimpleSAML\XMLSchema\XML\AnyAttribute|null $anyAttribute |
31
|
|
|
* @param \SimpleSAML\XMLSchema\Type\NCNameValue|null $name |
32
|
|
|
* @param \SimpleSAML\XMLSchema\Type\QNameValue|null $reference |
33
|
|
|
* @param \SimpleSAML\XMLSchema\XML\Annotation|null $annotation |
34
|
|
|
* @param \SimpleSAML\XMLSchema\Type\IDValue|null $id |
35
|
|
|
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes |
36
|
|
|
*/ |
37
|
|
|
public function __construct( |
38
|
|
|
array $attributes = [], |
39
|
|
|
?AnyAttribute $anyAttribute = null, |
40
|
|
|
?NCNameValue $name = null, |
41
|
|
|
?QNameValue $reference = null, |
42
|
|
|
protected ?Annotation $annotation = null, |
43
|
|
|
protected ?IDValue $id = null, |
44
|
|
|
array $namespacedAttributes = [], |
45
|
|
|
) { |
46
|
|
|
parent::__construct($annotation, $id, $namespacedAttributes); |
47
|
|
|
|
48
|
|
|
$this->setAttributes($attributes); |
49
|
|
|
$this->setAnyAttribute($anyAttribute); |
50
|
|
|
$this->setName($name); |
51
|
|
|
$this->setReference($reference); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Test if an object, at the state it's in, would produce an empty XML-element |
57
|
|
|
* |
58
|
|
|
* @return bool |
59
|
|
|
*/ |
60
|
|
|
public function isEmptyElement(): bool |
61
|
|
|
{ |
62
|
|
|
return parent::isEmptyElement() && |
63
|
|
|
empty($this->getName()) && |
64
|
|
|
empty($this->getReference()) && |
65
|
|
|
empty($this->getAttributes()) && |
66
|
|
|
empty($this->getAnyAttribute()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Add this Annotated to an XML element. |
72
|
|
|
* |
73
|
|
|
* @param \DOMElement|null $parent The element we should append this Annotated to. |
74
|
|
|
* @return \DOMElement |
75
|
|
|
*/ |
76
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
77
|
|
|
{ |
78
|
|
|
$e = parent::toXML($parent); |
79
|
|
|
|
80
|
|
|
if ($this->getName() !== null) { |
81
|
|
|
$e->setAttribute('name', strval($this->getName())); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
if ($this->getReference() !== null) { |
85
|
|
|
$e->setAttribute('ref', strval($this->getReference())); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
foreach ($this->getAttributes() as $attr) { |
89
|
|
|
$attr->toXML($e); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$this->getAnyAttribute()?->toXML($e); |
93
|
|
|
|
94
|
|
|
return $e; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|