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:X509IssuerName element. |
13
|
|
|
* |
14
|
|
|
* @package simplesaml/xml-security |
15
|
|
|
*/ |
16
|
|
|
final class X509IssuerName extends AbstractDsElement |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* The subject name. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected string $name; |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Initialize a X509IssuerName element. |
28
|
|
|
* |
29
|
|
|
* @param string $name |
30
|
|
|
*/ |
31
|
|
|
public function __construct(string $name) |
32
|
|
|
{ |
33
|
|
|
$this->setName($name); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Collect the value of the name-property |
39
|
|
|
* |
40
|
|
|
* @return string |
41
|
|
|
*/ |
42
|
|
|
public function getName(): string |
43
|
|
|
{ |
44
|
|
|
return $this->name; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Set the value of the name-property |
50
|
|
|
* |
51
|
|
|
* @param string $name |
52
|
|
|
*/ |
53
|
|
|
private function setName(string $name): void |
54
|
|
|
{ |
55
|
|
|
Assert::notEmpty($name, 'ds:X509IssuerName cannot be empty.'); |
56
|
|
|
$this->name = $name; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Convert XML into a X509IssuerName |
62
|
|
|
* |
63
|
|
|
* @param \DOMElement $xml The XML element we should load |
64
|
|
|
* @return self |
65
|
|
|
* |
66
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
67
|
|
|
* If the qualified name of the supplied element is wrong |
68
|
|
|
*/ |
69
|
|
|
public static function fromXML(DOMElement $xml): object |
70
|
|
|
{ |
71
|
|
|
Assert::same($xml->localName, 'X509IssuerName', InvalidDOMElementException::class); |
72
|
|
|
Assert::same($xml->namespaceURI, X509IssuerName::NS, InvalidDOMElementException::class); |
73
|
|
|
|
74
|
|
|
return new self($xml->textContent); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Convert this X509IssuerName element to XML. |
80
|
|
|
* |
81
|
|
|
* @param \DOMElement|null $parent The element we should append this X509IssuerName element to. |
82
|
|
|
* @return \DOMElement |
83
|
|
|
*/ |
84
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
85
|
|
|
{ |
86
|
|
|
$e = $this->instantiateParentElement($parent); |
87
|
|
|
$e->textContent = $this->name; |
88
|
|
|
|
89
|
|
|
return $e; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|