diff --git a/src/XML/wsse/AbstractEmbeddedType.php b/src/XML/wsse/AbstractEmbeddedType.php new file mode 100644 index 00000000..04e24c07 --- /dev/null +++ b/src/XML/wsse/AbstractEmbeddedType.php @@ -0,0 +1,116 @@ +setChildren($children); + $this->setAttributesNS($namespacedAttributes); + } + + + /** + * @return string + */ + public function getValueType(): string + { + return $this->valueType; + } + + + /** + * Create an instance of this object from its XML representation. + * + * @param \DOMElement $xml + * @return static + * + * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException + * if the qualified name of the supplied element is wrong + */ + public static function fromXML(DOMElement $xml): static + { + Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); + + $children = []; + foreach ($xml->childNodes as $child) { + if (!($child instanceof DOMElement)) { + continue; + } + + $children[] = new Chunk($child); + } + + return new static( + self::getAttribute($xml, 'ValueType'), + $children, + self::getAttributesNSFromXML($xml), + ); + } + + + /** + * Add this username token to an XML element. + * + * @param \DOMElement $parent The element we should append this username token to. + * @return \DOMElement + */ + public function toXML(DOMElement $parent = null): DOMElement + { + $e = parent::instantiateParentElement($parent); + $e->setAttribute('ValueType', $this->getValueType()); + + foreach ($this->getAttributesNS() as $attr) { + $attr->toXML($e); + } + + /** @psalm-var \SimpleSAML\XML\SerializableElementInterface $child */ + foreach ($this->getElements() as $child) { + if (!$child->isEmptyElement()) { + $child->toXML($e); + } + } + + return $e; + } +}