diff --git a/src/XML/fed/AbstractAttributeExtensibleURIType.php b/src/XML/fed/AbstractAttributeExtensibleURIType.php new file mode 100644 index 00000000..f06e6f58 --- /dev/null +++ b/src/XML/fed/AbstractAttributeExtensibleURIType.php @@ -0,0 +1,87 @@ +setContent($content); + $this->setAttributesNS($namespacedAttributes); + } + + + /** + * Validate the content of the element. + * + * @param string $content The value to go in the XML textContent + * @throws \SimpleSAML\XML\Exception\SchemaViolationException on failure + * @return void + */ + protected function validateContent(string $content): void + { + Assert::validURI($content, SchemaViolationException::class); + } + + + /** + * Create a class from XML + * + * @param \DOMElement $xml + * @return static + */ + public static function fromXML(DOMElement $xml): static + { + Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); + + return new static( + $xml->textContent, + self::getAttributesNSFromXML($xml), + ); + } + + + /** + * Create XML from this class + * + * @param \DOMElement|null $parent + * @return \DOMElement + */ + public function toXML(DOMElement $parent = null): DOMElement + { + $e = $this->instantiateParentElement($parent); + $e->textContent = $this->getContent(); + + foreach ($this->getAttributesNS() as $attr) { + $attr->toXML($e); + } + + return $e; + } +} diff --git a/src/XML/fed/FederationID.php b/src/XML/fed/FederationID.php new file mode 100644 index 00000000..7dc129e3 --- /dev/null +++ b/src/XML/fed/FederationID.php @@ -0,0 +1,14 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($federationID), + ); + } +} diff --git a/tests/resources/xml/fed_FederationID.xml b/tests/resources/xml/fed_FederationID.xml new file mode 100644 index 00000000..be5ef1ff --- /dev/null +++ b/tests/resources/xml/fed_FederationID.xml @@ -0,0 +1 @@ +urn:x-simplesamlphp:namespace