|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\CAS\XML\cas; |
|
6
|
|
|
|
|
7
|
|
|
use DateTimeImmutable; |
|
8
|
|
|
use DOMElement; |
|
9
|
|
|
use SimpleSAML\Assert\Assert; |
|
10
|
|
|
use SimpleSAML\CAS\Constants as C; |
|
11
|
|
|
use SimpleSAML\CAS\Exception\ProtocolViolationException; |
|
12
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
|
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 \DateTimeImmutable $timestamp |
|
27
|
|
|
*/ |
|
28
|
|
|
final public function __construct( |
|
29
|
|
|
protected DateTimeImmutable $timestamp |
|
30
|
|
|
) { |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Retrieve the issue timestamp of this message. |
|
36
|
|
|
* |
|
37
|
|
|
* @return \DateTimeImmutable The issue timestamp of this message, as an UNIX timestamp |
|
38
|
|
|
*/ |
|
39
|
|
|
public function getTimestamp(): DateTimeImmutable |
|
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
|
|
|
$root = $this->instantiateParentElement($parent); |
|
53
|
|
|
$root->textContent = $this->getTimestamp()->format(C::DATETIME_FORMAT); |
|
54
|
|
|
|
|
55
|
|
|
return $root; |
|
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\XML\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(new DateTimeImmutable($xml->textContent)); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|