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\Assert\Assert as SAMLAssert; |
10
|
|
|
use SimpleSAML\SAML2\XML\StringElementTrait; |
11
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class representing SAML2 Action |
15
|
|
|
* |
16
|
|
|
* @package simplesamlphp/saml2 |
17
|
|
|
*/ |
18
|
|
|
final class Action extends AbstractSamlElement |
19
|
|
|
{ |
20
|
|
|
use StringElementTrait; |
|
|
|
|
21
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Initialize an Action. |
25
|
|
|
* |
26
|
|
|
* @param string $namespace This attribute was marked REQUIRED in the 2012 SAML errata (E36) |
27
|
|
|
* @param string $content |
28
|
|
|
*/ |
29
|
|
|
public function __construct( |
30
|
|
|
protected string $namespace, |
31
|
|
|
string $content, |
32
|
|
|
) { |
33
|
|
|
SAMLAssert::validURI($namespace); |
34
|
|
|
|
35
|
|
|
$this->setContent($content); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Collect the value of the namespace-property |
41
|
|
|
* |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
|
|
public function getNamespace(): string |
45
|
|
|
{ |
46
|
|
|
return $this->namespace; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Convert XML into a Action |
52
|
|
|
* |
53
|
|
|
* @param \DOMElement $xml The XML element we should load |
54
|
|
|
* @return static |
55
|
|
|
* |
56
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
57
|
|
|
* if the qualified name of the supplied element is wrong |
58
|
|
|
*/ |
59
|
|
|
public static function fromXML(DOMElement $xml): static |
60
|
|
|
{ |
61
|
|
|
Assert::same($xml->localName, 'Action', InvalidDOMElementException::class); |
62
|
|
|
Assert::same($xml->namespaceURI, Action::NS, InvalidDOMElementException::class); |
63
|
|
|
|
64
|
|
|
return new self( |
65
|
|
|
self::getAttribute($xml, 'Namespace'), |
66
|
|
|
$xml->textContent, |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Convert this Action to XML. |
73
|
|
|
* |
74
|
|
|
* @param \DOMElement|null $parent The element we should append this Action to. |
75
|
|
|
* @return \DOMElement |
76
|
|
|
*/ |
77
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
78
|
|
|
{ |
79
|
|
|
$e = $this->instantiateParentElement($parent); |
80
|
|
|
|
81
|
|
|
$e->setAttribute('Namespace', $this->getNamespace()); |
82
|
|
|
$e->textContent = $this->getContent(); |
83
|
|
|
|
84
|
|
|
return $e; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|