Skip to content

Commit

Permalink
Implement IntegerElementTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Nov 29, 2024
1 parent f945846 commit 5e7ad96
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 73 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
39 changes: 3 additions & 36 deletions src/XML/wst_200502/KeySize.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -17,7 +17,7 @@
*/
final class KeySize extends AbstractWstElement
{
use StringElementTrait;
use IntegerElementTrait;

/**
* KeySize constructor.
Expand All @@ -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;
}
}
39 changes: 3 additions & 36 deletions src/XML/wst_200512/KeySize.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -17,7 +17,7 @@
*/
final class KeySize extends AbstractWstElement
{
use StringElementTrait;
use IntegerElementTrait;

/**
* KeySize constructor.
Expand All @@ -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;
}
}

0 comments on commit 5e7ad96

Please sign in to comment.