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