1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\WSSecurity\XML\wsaw; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\XML\Attribute as XMLAttribute; |
10
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
11
|
|
|
use SimpleSAML\XML\ExtendableAttributesTrait; |
12
|
|
|
use SimpleSAML\XML\XsNamespace as NS; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class defining the Anonymous element |
16
|
|
|
* |
17
|
|
|
* @package simplesamlphp/ws-security |
18
|
|
|
*/ |
19
|
|
|
final class Anonymous extends AbstractAnonymousType |
20
|
|
|
{ |
21
|
|
|
use ExtendableAttributesTrait; |
22
|
|
|
|
23
|
|
|
/** The namespace-attribute for the xs:anyAttribute element */ |
24
|
|
|
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Anonymous constructor |
29
|
|
|
* |
30
|
|
|
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes |
31
|
|
|
*/ |
32
|
|
|
final public function __construct( |
33
|
|
|
AnonymousEnum $value, |
34
|
|
|
array $namespacedAttributes = [], |
35
|
|
|
) { |
36
|
|
|
parent::__construct($value); |
37
|
|
|
|
38
|
|
|
$this->setAttributesNS($namespacedAttributes); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Create an instance of this object from its XML representation. |
44
|
|
|
* |
45
|
|
|
* @param \DOMElement $xml |
46
|
|
|
* @return static |
47
|
|
|
* |
48
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
49
|
|
|
* if the qualified name of the supplied element is wrong |
50
|
|
|
*/ |
51
|
|
|
public static function fromXML(DOMElement $xml): static |
52
|
|
|
{ |
53
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
54
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
55
|
|
|
|
56
|
|
|
try { |
57
|
|
|
$anonymous = AnonymousEnum::from($xml->textContent); |
58
|
|
|
} catch (ValueError) { |
|
|
|
|
59
|
|
|
throw new SchemaViolationException(sprintf('Unknown value \'%s\' for Anonymous element.', $xml->textContent)); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return new static($anonymous, self::getAttributesNSFromXML($xml)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Convert this Anonymous to XML. |
68
|
|
|
* |
69
|
|
|
* @param \DOMElement|null $parent The element we should append this class to. |
70
|
|
|
* @return \DOMElement The XML element after adding the data corresponding to this Anonymous. |
71
|
|
|
*/ |
72
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
73
|
|
|
{ |
74
|
|
|
$e = parent::toXML($parent); |
75
|
|
|
|
76
|
|
|
foreach ($this->getAttributesNS() as $attr) { |
77
|
|
|
$attr->toXML($e); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $e; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|