1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\WSSecurity\XML\wst_200512; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\WSSecurity\Assert\Assert; |
9
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
10
|
|
|
use SimpleSAML\XML\Exception\MissingElementException; |
11
|
|
|
use SimpleSAML\XML\Exception\TooManyElementsException; |
12
|
|
|
use SimpleSAML\XML\ExtendableElementTrait; |
13
|
|
|
use SimpleSAML\XML\SerializableElementInterface; |
14
|
|
|
use SimpleSAML\XML\XsNamespace as NS; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class defining the ProofEncryptionType element |
18
|
|
|
* |
19
|
|
|
* @package simplesamlphp/ws-security |
20
|
|
|
*/ |
21
|
|
|
abstract class AbstractProofEncryptionType extends AbstractWstElement |
22
|
|
|
{ |
23
|
|
|
use ExtendableElementTrait; |
|
|
|
|
24
|
|
|
|
25
|
|
|
/** The namespace-attribute for the xs:any element */ |
26
|
|
|
public const XS_ANY_ELT_NAMESPACE = NS::ANY; |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* AbstractProofEncryptionType constructor |
31
|
|
|
* |
32
|
|
|
* @param \SimpleSAML\XML\SerializableElementInterface $child |
33
|
|
|
*/ |
34
|
|
|
final public function __construct( |
35
|
|
|
SerializableElementInterface $child, |
36
|
|
|
) { |
37
|
|
|
$this->setElements([$child]); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Create an instance of this object from its XML representation. |
43
|
|
|
* |
44
|
|
|
* @param \DOMElement $xml |
45
|
|
|
* @return static |
46
|
|
|
* |
47
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
48
|
|
|
* if the qualified name of the supplied element is wrong |
49
|
|
|
*/ |
50
|
|
|
public static function fromXML(DOMElement $xml): static |
51
|
|
|
{ |
52
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
53
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
54
|
|
|
|
55
|
|
|
$children = self::getChildElementsFromXML($xml); |
56
|
|
|
Assert::minCount($children, 1, MissingElementException::class); |
57
|
|
|
Assert::maxCount($children, 1, TooManyElementsException::class); |
58
|
|
|
|
59
|
|
|
return new static( |
60
|
|
|
array_pop($children), |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Add this ProofEncryptionType to an XML element. |
67
|
|
|
* |
68
|
|
|
* @param \DOMElement|null $parent The element we should append this username token to. |
69
|
|
|
* @return \DOMElement |
70
|
|
|
*/ |
71
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
72
|
|
|
{ |
73
|
|
|
$e = parent::instantiateParentElement($parent); |
74
|
|
|
|
75
|
|
|
foreach ($this->getElements() as $child) { |
76
|
|
|
if (!$child->isEmptyElement()) { |
77
|
|
|
$child->toXML($e); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $e; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|