simplesamlphp /
xml-cas
| 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/xml-cas |
||
| 18 | */ |
||
| 19 | final class AuthenticationDate extends AbstractCasElement |
||
| 20 | { |
||
| 21 | final public const string LOCALNAME = 'authenticationDate'; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 22 | |||
| 23 | |||
| 24 | /** |
||
| 25 | * @param \SimpleSAML\XMLSchema\Type\DateTimeValue $timestamp |
||
| 26 | */ |
||
| 27 | final public function __construct( |
||
| 28 | protected DateTimeValue $timestamp, |
||
| 29 | ) { |
||
| 30 | } |
||
| 31 | |||
| 32 | |||
| 33 | /** |
||
| 34 | * Retrieve the issue timestamp of this message. |
||
| 35 | * |
||
| 36 | * @return \SimpleSAML\XMLSchema\Type\DateTimeValue The issue timestamp of this message |
||
| 37 | */ |
||
| 38 | public function getTimestamp(): DateTimeValue |
||
| 39 | { |
||
| 40 | return $this->timestamp; |
||
| 41 | } |
||
| 42 | |||
| 43 | |||
| 44 | /** |
||
| 45 | * Convert this element into an XML document. |
||
| 46 | * |
||
| 47 | * @return \DOMElement The root element of the DOM tree |
||
| 48 | */ |
||
| 49 | public function toXML(?DOMElement $parent = null): DOMElement |
||
| 50 | { |
||
| 51 | $e = $this->instantiateParentElement($parent); |
||
| 52 | $e->textContent = strval($this->getTimestamp()); |
||
| 53 | |||
| 54 | return $e; |
||
| 55 | } |
||
| 56 | |||
| 57 | |||
| 58 | /** |
||
| 59 | * Convert XML into a cas:authenticationDate |
||
| 60 | * |
||
| 61 | * @param \DOMElement $xml The XML element we should load |
||
| 62 | * @return static |
||
| 63 | * |
||
| 64 | * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
||
| 65 | * If the qualified name of the supplied element is wrong |
||
| 66 | */ |
||
| 67 | public static function fromXML(DOMElement $xml): static |
||
| 68 | { |
||
| 69 | Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
||
| 70 | Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); |
||
| 71 | |||
| 72 | return new static(DateTimeValue::fromString($xml->textContent)); |
||
| 73 | } |
||
| 74 | } |
||
| 75 |