1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML2\XML\samlp; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\SAML2\Exception\ArrayValidationException; |
10
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
11
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
12
|
|
|
use SimpleSAML\XML\StringElementTrait; |
13
|
|
|
|
14
|
|
|
use function array_key_first; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class representing a samlp:RequesterID element. |
18
|
|
|
* |
19
|
|
|
* @package simplesaml/saml2 |
20
|
|
|
*/ |
21
|
|
|
final class RequesterID extends AbstractSamlpElement |
22
|
|
|
{ |
23
|
|
|
use StringElementTrait; |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param string $content |
28
|
|
|
*/ |
29
|
|
|
public function __construct(string $content) |
30
|
|
|
{ |
31
|
|
|
$this->setContent($content); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Validate the content of the element. |
37
|
|
|
* |
38
|
|
|
* @param string $content The value to go in the XML textContent |
39
|
|
|
* @throws \Exception on failure |
40
|
|
|
* @return void |
41
|
|
|
*/ |
42
|
|
|
protected function validateContent(string $content): void |
43
|
|
|
{ |
44
|
|
|
Assert::validURI($content, SchemaViolationException::class); // Covers the empty string |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Convert XML into an RequesterID |
50
|
|
|
* |
51
|
|
|
* @param \DOMElement $xml The XML element we should load |
52
|
|
|
* @return static |
53
|
|
|
* |
54
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
55
|
|
|
* If the qualified name of the supplied element is wrong |
56
|
|
|
*/ |
57
|
|
|
public static function fromXML(DOMElement $xml): static |
58
|
|
|
{ |
59
|
|
|
Assert::same($xml->localName, 'RequesterID', InvalidDOMElementException::class); |
60
|
|
|
Assert::same($xml->namespaceURI, RequesterID::NS, InvalidDOMElementException::class); |
61
|
|
|
|
62
|
|
|
return new static($xml->textContent); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Create a class from an array |
68
|
|
|
* |
69
|
|
|
* @param array $data |
70
|
|
|
* @return static |
71
|
|
|
*/ |
72
|
|
|
public static function fromArray(array $data): static |
73
|
|
|
{ |
74
|
|
|
Assert::allString($data, ArrayValidationException::class); |
75
|
|
|
|
76
|
|
|
$index = array_key_first($data); |
77
|
|
|
return new static($data[$index]); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Create an array from this class |
83
|
|
|
* |
84
|
|
|
* @return array |
85
|
|
|
*/ |
86
|
|
|
public function toArray(): array |
87
|
|
|
{ |
88
|
|
|
return [$this->getContent()]; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|