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