1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML2\XML\saml; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\SAML2\Constants; |
10
|
|
|
use SimpleSAML\SAML2\Utils; |
11
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
12
|
|
|
|
13
|
|
|
use function trim; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* SAML Condition data type. |
17
|
|
|
* |
18
|
|
|
* @package simplesamlphp/saml2 |
19
|
|
|
*/ |
20
|
|
|
abstract class Condition extends AbstractConditionType |
21
|
|
|
{ |
22
|
|
|
/** @var string */ |
23
|
|
|
public const LOCALNAME = 'Condition'; |
24
|
|
|
|
25
|
|
|
/** @var string */ |
26
|
|
|
protected string $type; |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Initialize a saml:Condition from scratch |
31
|
|
|
* |
32
|
|
|
* @param string $content |
33
|
|
|
* @param string $type |
34
|
|
|
*/ |
35
|
|
|
protected function __construct( |
36
|
|
|
string $content, |
37
|
|
|
string $type |
38
|
|
|
) { |
39
|
|
|
$this->setContent($content); |
40
|
|
|
$this->setType($type); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get the type of this Condition (expressed in the xsi:type attribute). |
46
|
|
|
* |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
public function getType(): string |
50
|
|
|
{ |
51
|
|
|
return $this->type; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Set the type of this Condition (in the xsi:type attribute) |
57
|
|
|
* |
58
|
|
|
* @param string $type |
59
|
|
|
*/ |
60
|
|
|
protected function setType(string $type): void |
61
|
|
|
{ |
62
|
|
|
Assert::notWhitespaceOnly($type, 'The "xsi:type" attribute of a Condition cannot be empty.'); |
63
|
|
|
Assert::contains($type, ':'); |
64
|
|
|
|
65
|
|
|
$this->type = $type; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Convert this Condition to XML. |
71
|
|
|
* |
72
|
|
|
* @param \DOMElement $parent The element we are converting to XML. |
73
|
|
|
* @return \DOMElement The XML element after adding the data corresponding to this Condition. |
74
|
|
|
*/ |
75
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
76
|
|
|
{ |
77
|
|
|
$e = $this->instantiateParentElement($parent); |
78
|
|
|
|
79
|
|
|
$e->setAttribute('xmlns:' . static::XSI_TYPE_PREFIX, static::XSI_TYPE_NS); |
|
|
|
|
80
|
|
|
$e->setAttributeNS(Constants::NS_XSI, 'xsi:type', $this->type); |
81
|
|
|
|
82
|
|
|
return $e; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|