1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\CAS\XML; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\CAS\Assert\Assert; |
9
|
|
|
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException; |
10
|
|
|
use SimpleSAML\XMLSchema\Type\DateTimeValue; |
11
|
|
|
|
12
|
|
|
use function strval; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class for CAS authenticationDate |
16
|
|
|
* |
17
|
|
|
* @package simplesamlphp/cas |
18
|
|
|
*/ |
19
|
|
|
final class AuthenticationDate extends AbstractCasElement |
20
|
|
|
{ |
21
|
|
|
/** @var string */ |
22
|
|
|
final public const LOCALNAME = 'authenticationDate'; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param \SimpleSAML\XMLSchema\Type\DateTimeValue $timestamp |
27
|
|
|
*/ |
28
|
|
|
final public function __construct( |
29
|
|
|
protected DateTimeValue $timestamp, |
30
|
|
|
) { |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Retrieve the issue timestamp of this message. |
36
|
|
|
* |
37
|
|
|
* @return \SimpleSAML\XMLSchema\Type\DateTimeValue The issue timestamp of this message |
38
|
|
|
*/ |
39
|
|
|
public function getTimestamp(): DateTimeValue |
40
|
|
|
{ |
41
|
|
|
return $this->timestamp; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Convert this element into an XML document. |
47
|
|
|
* |
48
|
|
|
* @return \DOMElement The root element of the DOM tree |
49
|
|
|
*/ |
50
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
51
|
|
|
{ |
52
|
|
|
$e = $this->instantiateParentElement($parent); |
53
|
|
|
$e->textContent = strval($this->getTimestamp()); |
54
|
|
|
|
55
|
|
|
return $e; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Convert XML into a cas:authenticationDate |
61
|
|
|
* |
62
|
|
|
* @param \DOMElement $xml The XML element we should load |
63
|
|
|
* @return static |
64
|
|
|
* |
65
|
|
|
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
66
|
|
|
* If the qualified name of the supplied element is wrong |
67
|
|
|
*/ |
68
|
|
|
public static function fromXML(DOMElement $xml): static |
69
|
|
|
{ |
70
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
71
|
|
|
Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); |
72
|
|
|
|
73
|
|
|
return new static(DateTimeValue::fromString($xml->textContent)); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|