1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML11\XML\saml; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\SAML11\Type\{SAMLAnyURIValue, SAMLStringValue}; |
10
|
|
|
use SimpleSAML\XMLSchema\Exception\{InvalidDOMElementException, SchemaViolationException}; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* SAML AttributeType abstract data type. |
14
|
|
|
* |
15
|
|
|
* @package simplesamlphp/saml11 |
16
|
|
|
*/ |
17
|
|
|
abstract class AbstractAttributeType extends AbstractAttributeDesignatorType |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Initialize a saml:AttributeType from scratch |
21
|
|
|
* |
22
|
|
|
* @param \SimpleSAML\SAML11\Type\SAMLStringValue $AttributeName |
23
|
|
|
* @param \SimpleSAML\SAML11\Type\SAMLAnyURIValue $AttributeNamespace |
24
|
|
|
* @param array<\SimpleSAML\SAML11\XML\saml\AttributeValue> $attributeValue |
25
|
|
|
*/ |
26
|
|
|
final public function __construct( |
27
|
|
|
SAMLStringValue $AttributeName, |
28
|
|
|
SAMLAnyURIValue $AttributeNamespace, |
29
|
|
|
protected array $attributeValue, |
30
|
|
|
) { |
31
|
|
|
Assert::allIsInstanceOf($attributeValue, AttributeValue::class, SchemaViolationException::class); |
32
|
|
|
|
33
|
|
|
parent::__construct($AttributeName, $AttributeNamespace); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Collect the value of the attributeValue-property |
39
|
|
|
* |
40
|
|
|
* @return array<\SimpleSAML\SAML11\XML\saml\AttributeValue> |
41
|
|
|
*/ |
42
|
|
|
public function getAttributeValue(): array |
43
|
|
|
{ |
44
|
|
|
return $this->attributeValue; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Convert XML into an AttributeType |
50
|
|
|
* |
51
|
|
|
* @param \DOMElement $xml The XML element we should load |
52
|
|
|
* @return static |
53
|
|
|
* |
54
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
55
|
|
|
* if the qualified name of the supplied element is wrong |
56
|
|
|
*/ |
57
|
|
|
public static function fromXML(DOMElement $xml): static |
58
|
|
|
{ |
59
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
60
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
61
|
|
|
|
62
|
|
|
$attributeValue = AttributeValue::getChildrenOfClass($xml); |
63
|
|
|
$AttributeName = self::getAttribute($xml, 'AttributeName', SAMLStringValue::class); |
64
|
|
|
$AttributeNamespace = self::getAttribute($xml, 'AttributeNamespace', SAMLAnyURIValue::class); |
65
|
|
|
|
66
|
|
|
return new static($AttributeName, $AttributeNamespace, $attributeValue); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Convert this AttributeType to XML. |
72
|
|
|
* |
73
|
|
|
* @param \DOMElement $parent The element we are converting to XML. |
74
|
|
|
* @return \DOMElement The XML element after adding the data corresponding to this AttributeType. |
75
|
|
|
*/ |
76
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
77
|
|
|
{ |
78
|
|
|
$e = parent::toXML($parent); |
79
|
|
|
|
80
|
|
|
foreach ($this->getAttributeValue() as $av) { |
81
|
|
|
$av->toXML($e); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $e; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|