1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\XML\xenc; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
10
|
|
|
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; |
11
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\Transform; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class representing a xenc:Transforms element. |
15
|
|
|
* |
16
|
|
|
* @package simplesamlphp/xml-security |
17
|
|
|
*/ |
18
|
|
|
final class Transforms extends AbstractXencElement |
19
|
|
|
{ |
20
|
|
|
/** @var \SimpleSAML\XMLSecurity\XML\ds\Transform[] */ |
21
|
|
|
protected array $transform; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Initialize a xenc:Transforms |
26
|
|
|
* |
27
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\ds\Transform[] $transform |
28
|
|
|
*/ |
29
|
|
|
public function __construct(array $transform) |
30
|
|
|
{ |
31
|
|
|
$this->setTransform($transform); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return \SimpleSAML\XMLSecurity\XML\ds\Transform[] |
37
|
|
|
*/ |
38
|
|
|
public function getTransform(): array |
39
|
|
|
{ |
40
|
|
|
return $this->transform; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\ds\Transform[] $transform |
46
|
|
|
*/ |
47
|
|
|
protected function setTransform(array $transform): void |
48
|
|
|
{ |
49
|
|
|
Assert::allIsInstanceOf($transform, Transform::class, InvalidArgumentException::class); |
50
|
|
|
$this->transform = $transform; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Test if an object, at the state it's in, would produce an empty XML-element |
56
|
|
|
* |
57
|
|
|
* @return bool |
58
|
|
|
*/ |
59
|
|
|
public function isEmptyElement(): bool |
60
|
|
|
{ |
61
|
|
|
return empty($this->transform); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Convert XML into a Transforms element |
67
|
|
|
* |
68
|
|
|
* @param \DOMElement $xml The XML element we should load |
69
|
|
|
* @return self |
70
|
|
|
* |
71
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
72
|
|
|
* If the qualified name of the supplied element is wrong |
73
|
|
|
*/ |
74
|
|
|
public static function fromXML(DOMElement $xml): self |
75
|
|
|
{ |
76
|
|
|
Assert::same($xml->localName, 'Transforms', InvalidDOMElementException::class); |
77
|
|
|
Assert::same($xml->namespaceURI, Transforms::NS, InvalidDOMElementException::class); |
78
|
|
|
|
79
|
|
|
$transform = Transform::getChildrenOfClass($xml); |
80
|
|
|
|
81
|
|
|
return new self($transform); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Convert this Transforms element to XML. |
87
|
|
|
* |
88
|
|
|
* @param \DOMElement|null $parent The element we should append this Transforms element to. |
89
|
|
|
* @return \DOMElement |
90
|
|
|
*/ |
91
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
92
|
|
|
{ |
93
|
|
|
$e = $this->instantiateParentElement($parent); |
94
|
|
|
|
95
|
|
|
foreach ($this->transform as $t) { |
96
|
|
|
if (!$t->isEmptyElement()) { |
97
|
|
|
$t->toXML($e); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return $e; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|