44
55namespace SimpleSAML \WSSecurity \XML \wsu ;
66
7- use DateTimeImmutable ;
87use DOMElement ;
98use SimpleSAML \WSSecurity \Assert \Assert ;
109use SimpleSAML \WSSecurity \Constants as C ;
1110use SimpleSAML \WSSecurity \Exception \ProtocolViolationException ;
11+ use SimpleSAML \WSSecurity \XML \wsu \Type \IDValue ;
12+ use SimpleSAML \WSSecurity \XML \wsu \Type \DateTimeValue ;
1213use SimpleSAML \XML \Attribute as XMLAttribute ;
13- use SimpleSAML \XML \Exception \InvalidDOMElementException ;
1414use SimpleSAML \XML \ExtendableAttributesTrait ;
15- use SimpleSAML \XML \XsNamespace as NS ;
15+ use SimpleSAML \XMLSchema \Exception \InvalidDOMElementException ;
16+ use SimpleSAML \XMLSchema \XML \Constants \NS ;
1617
1718/**
1819 * Abstract class defining the AttributedDateTime type
@@ -30,24 +31,23 @@ abstract class AbstractAttributedDateTime extends AbstractWsuElement
3031 /**
3132 * AbstractAttributedDateTime constructor
3233 *
33- * @param \DateTimeImmutable $dateTime
34- * @param string |null $Id
34+ * @param \SimpleSAML\WSSecurity\XML\wsu\Type\DateTimeValue $dateTime
35+ * @param \SimpleSAML\WSSecurity\XML\wsu\Type\IDValue |null $Id
3536 * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
3637 */
3738 final public function __construct (
38- protected DateTimeImmutable $ dateTime ,
39- protected ?string $ Id = null ,
39+ protected DateTimeValue $ dateTime ,
40+ protected ?IDValue $ Id = null ,
4041 array $ namespacedAttributes = [],
4142 ) {
42- Assert::nullOrValidNCName ($ Id );
4343 $ this ->setAttributesNS ($ namespacedAttributes );
4444 }
4545
4646
4747 /**
48- * @return string |null
48+ * @return \SimpleSAML\WSSecurity\XML\wsu\Type\IDValue |null
4949 */
50- public function getId (): ?string
50+ public function getId (): ?IDValue
5151 {
5252 return $ this ->Id ;
5353 }
@@ -56,9 +56,9 @@ public function getId(): ?string
5656 /**
5757 * Collect the value of the dateTime property
5858 *
59- * @return \DateTimeImmutable
59+ * @return \SimpleSAML\WSSecurity\XML\wsu\Type\DateTimeValue
6060 */
61- public function getDateTime (): DateTimeImmutable
61+ public function getDateTime (): DateTimeValue
6262 {
6363 return $ this ->dateTime ;
6464 }
@@ -70,25 +70,20 @@ public function getDateTime(): DateTimeImmutable
7070 * @param \DOMElement $xml
7171 * @return static
7272 *
73- * @throws \SimpleSAML\XML \Exception\InvalidDOMElementException
73+ * @throws \SimpleSAML\XMLSchema \Exception\InvalidDOMElementException
7474 * if the qualified name of the supplied element is wrong
7575 */
7676 public static function fromXML (DOMElement $ xml ): static
7777 {
7878 Assert::same ($ xml ->localName , static ::getLocalName (), InvalidDOMElementException::class);
7979 Assert::same ($ xml ->namespaceURI , static ::NS , InvalidDOMElementException::class);
8080
81- // Time values MUST be expressed in the UTC timezone using the 'Z' timezone identifier
82- // Strip sub-seconds
83- $ xml ->textContent = preg_replace ('/([.][0-9]+)/ ' , '' , $ xml ->textContent , 1 );
84- Assert::validDateTime ($ xml ->textContent , ProtocolViolationException::class);
85-
8681 $ Id = null ;
8782 if ($ xml ->hasAttributeNS (static ::NS , 'Id ' )) {
88- $ Id = $ xml ->getAttributeNS (static ::NS , 'Id ' );
83+ $ Id = IDValue:: fromString ( $ xml ->getAttributeNS (static ::NS , 'Id ' ) );
8984 }
9085
91- return new static (new DateTimeImmutable ($ xml ->textContent ), $ Id , self ::getAttributesNSFromXML ($ xml ));
86+ return new static (DateTimeValue:: fromString ($ xml ->textContent ), $ Id , self ::getAttributesNSFromXML ($ xml ));
9287 }
9388
9489
@@ -99,11 +94,11 @@ public static function fromXML(DOMElement $xml): static
9994 final public function toXML (?DOMElement $ parent = null ): DOMElement
10095 {
10196 $ e = $ this ->instantiateParentElement ($ parent );
102- $ e ->textContent = $ this ->getDateTime ()->format (C:: DATETIME_FORMAT );
97+ $ e ->textContent = $ this ->getDateTime ()->getValue ( );
10398
10499 $ attributes = $ this ->getAttributesNS ();
105100 if ($ this ->getId () !== null ) {
106- $ attributes [] = new XMLAttribute ( static :: NS , ' wsu ' , ' Id ' , $ this ->getId ());
101+ $ this ->getId ()-> toAttribute ()-> toXML ( $ e );
107102 }
108103
109104 foreach ($ attributes as $ attr ) {
0 commit comments