1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\WSSecurity\XML\wsdl; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
10
|
|
|
|
11
|
|
|
use function array_map; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Abstract class representing the tMessage type. |
15
|
|
|
* |
16
|
|
|
* @package simplesamlphp/ws-security |
17
|
|
|
*/ |
18
|
|
|
abstract class AbstractMessage extends AbstractExtensibleDocumented |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Initialize a wsdl:tMessage |
22
|
|
|
* |
23
|
|
|
* @param string $name |
24
|
|
|
* @param \SimpleSAML\WSSecurity\XML\wsdl\Part[] $parts |
25
|
|
|
* @param \SimpleSAML\XML\Chunk[] $elements |
26
|
|
|
*/ |
27
|
|
|
public function __construct( |
28
|
|
|
protected string $name, |
29
|
|
|
protected array $parts, |
30
|
|
|
array $elements = [], |
31
|
|
|
) { |
32
|
|
|
Assert::validNCName($name, SchemaViolationException::class); |
33
|
|
|
Assert::allIsInstanceOf($parts, Part::class, SchemaViolationException::class); |
34
|
|
|
|
35
|
|
|
$partNames = array_map( |
36
|
|
|
function ($x) { |
37
|
|
|
return $x->getName(); |
38
|
|
|
}, |
39
|
|
|
$parts, |
40
|
|
|
); |
41
|
|
|
Assert::uniqueValues($partNames, "Part-elements must have unique names.", SchemaViolationException::class); |
42
|
|
|
|
43
|
|
|
parent::__construct($elements); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Collect the value of the name-property. |
49
|
|
|
* |
50
|
|
|
* @return string |
51
|
|
|
*/ |
52
|
|
|
public function getName(): string |
53
|
|
|
{ |
54
|
|
|
return $this->name; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Collect the value of the parts-property. |
60
|
|
|
* |
61
|
|
|
* @return \SimpleSAML\WSSecurity\XML\wsdl\Part[] |
62
|
|
|
*/ |
63
|
|
|
public function getParts(): array |
64
|
|
|
{ |
65
|
|
|
return $this->parts; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Test if an object, at the state it's in, would produce an empty XML-element |
71
|
|
|
* |
72
|
|
|
* @return bool |
73
|
|
|
*/ |
74
|
|
|
public function isEmptyElement(): bool |
75
|
|
|
{ |
76
|
|
|
// Upstream abstract elements can be empty, but this one cannot |
77
|
|
|
return false; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Convert this tParam to XML. |
83
|
|
|
* |
84
|
|
|
* @param \DOMElement|null $parent The element we are converting to XML. |
85
|
|
|
* @return \DOMElement The XML element after adding the data corresponding to this tParam. |
86
|
|
|
*/ |
87
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
88
|
|
|
{ |
89
|
|
|
$e = parent::toXML($parent); |
90
|
|
|
$e->setAttribute('name', $this->getName()); |
91
|
|
|
|
92
|
|
|
foreach ($this->getParts() as $part) { |
93
|
|
|
$part->toXML($e); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return $e; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|