From 5e7ad9629a322638146869032bcb2f73a8af417a Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Fri, 29 Nov 2024 23:30:40 +0100 Subject: [PATCH] Implement IntegerElementTrait --- composer.json | 2 +- src/XML/wst_200502/KeySize.php | 39 +++------------------------------- src/XML/wst_200512/KeySize.php | 39 +++------------------------------- 3 files changed, 7 insertions(+), 73 deletions(-) diff --git a/composer.json b/composer.json index ecb55982..988bbbe8 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "simplesamlphp/composer-xmlprovider-installer": "~1.0.0", "simplesamlphp/saml2": "^5@dev", "simplesamlphp/xml-security": "^1.7", - "simplesamlphp/xml-common": "^1.16" + "simplesamlphp/xml-common": "^1.19" }, "require-dev": { "simplesamlphp/simplesamlphp-test-framework": "^1.5" diff --git a/src/XML/wst_200502/KeySize.php b/src/XML/wst_200502/KeySize.php index 669e3129..5960948f 100644 --- a/src/XML/wst_200502/KeySize.php +++ b/src/XML/wst_200502/KeySize.php @@ -8,7 +8,7 @@ use SimpleSAML\Assert\Assert; use SimpleSAML\XML\Exception\InvalidDOMElementException; use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\StringElementTrait; +use SimpleSAML\XML\IntegerElementTrait; /** * Class representing WS-trust KeySize. @@ -17,7 +17,7 @@ */ final class KeySize extends AbstractWstElement { - use StringElementTrait; + use IntegerElementTrait; /** * KeySize constructor. @@ -40,40 +40,7 @@ final public function __construct(string $value) protected function validateContent(string $content): void { $content = intval($content); - Assert::natural($content); + Assert::natural($content, SchemaViolationException::class); Assert::range($content, 0, 4294967295, SchemaViolationException::class); } - - - /** - * Convert XML into a class instance - * - * @param \DOMElement $xml The XML element we should load - * @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); - - return new static($xml->textContent); - } - - - /** - * Convert this element to XML. - * - * @param \DOMElement|null $parent The element we should append this element to. - * @return \DOMElement - */ - public function toXML(DOMElement $parent = null): DOMElement - { - $e = $this->instantiateParentElement($parent); - $e->textContent = $this->getContent(); - - return $e; - } } diff --git a/src/XML/wst_200512/KeySize.php b/src/XML/wst_200512/KeySize.php index 1571a250..ce4ee6c2 100644 --- a/src/XML/wst_200512/KeySize.php +++ b/src/XML/wst_200512/KeySize.php @@ -8,7 +8,7 @@ use SimpleSAML\Assert\Assert; use SimpleSAML\XML\Exception\InvalidDOMElementException; use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\StringElementTrait; +use SimpleSAML\XML\IntegerElementTrait; /** * Class representing WS-trust KeySize. @@ -17,7 +17,7 @@ */ final class KeySize extends AbstractWstElement { - use StringElementTrait; + use IntegerElementTrait; /** * KeySize constructor. @@ -40,40 +40,7 @@ final public function __construct(string $value) protected function validateContent(string $content): void { $content = intval($content); - Assert::natural($content); + Assert::natural($content, SchemaViolationException::class); Assert::range($content, 0, 4294967295, SchemaViolationException::class); } - - - /** - * Convert XML into a class instance - * - * @param \DOMElement $xml The XML element we should load - * @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); - - return new static($xml->textContent); - } - - - /** - * Convert this element to XML. - * - * @param \DOMElement|null $parent The element we should append this element to. - * @return \DOMElement - */ - public function toXML(DOMElement $parent = null): DOMElement - { - $e = $this->instantiateParentElement($parent); - $e->textContent = $this->getContent(); - - return $e; - } }