diff --git a/src/XML/wst/AbstractBinarySecretTypeOpenEnumType.php b/src/XML/wst/AbstractBinarySecretTypeOpenEnumType.php index 0d2b941c..dd2f0dfa 100644 --- a/src/XML/wst/AbstractBinarySecretTypeOpenEnumType.php +++ b/src/XML/wst/AbstractBinarySecretTypeOpenEnumType.php @@ -4,7 +4,15 @@ namespace SimpleSAML\WSSecurity\XML\wst; -use SimpleSAML\XML\URIElementTrait; +use DOMElement; +use SimpleSAML\Assert\Assert; +use SimpleSAML\XML\Exception\InvalidDOMElementException; +use SimpleSAML\XML\Exception\SchemaViolationException; +use SimpleSAML\XML\StringElementTrait; + +use function array_map; +use function explode; +use function implode; /** * A BinarySecretTypeOpenEnum element @@ -13,18 +21,40 @@ */ abstract class AbstractBinarySecretTypeOpenEnum extends AbstractWstElement { - use URIElementTrait; + use StringElementTrait; + + + /** + * @param string[] $values + */ + public function __construct(array $values) + { + $values = array_map( + function (BinarySecretTypeEnum|string $v): string { + return ($v instanceof BinarySecretTypeEnum) ? $v->value : $v; + }, + $values, + ); + Assert::allValidURI($values, SchemaViolationException::class); + + $this->setContent(implode(' ', $values)); + } /** - * @param \SimpleSAML\WSSecurity\XML\wst\BinarySecretTypeEnum|string $content + * 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 function __construct(BinarySecretTypeEnum|string $content) + public static function fromXML(DOMElement $xml): static { - if ($content instanceof BinarySecretTypeEnum) { - $content = $content->value; - } + Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); - $this->setContent($content); + return new static(explode(' ', $xml->textContent)); } } diff --git a/src/XML/wst/AbstractComputedKeyOpenEnum.php b/src/XML/wst/AbstractComputedKeyOpenEnum.php index f8e39403..a29fe75e 100644 --- a/src/XML/wst/AbstractComputedKeyOpenEnum.php +++ b/src/XML/wst/AbstractComputedKeyOpenEnum.php @@ -4,7 +4,15 @@ namespace SimpleSAML\WSSecurity\XML\wst; -use SimpleSAML\XML\URIElementTrait; +use DOMElement; +use SimpleSAML\Assert\Assert; +use SimpleSAML\XML\Exception\InvalidDOMElementException; +use SimpleSAML\XML\Exception\SchemaViolationException; +use SimpleSAML\XML\StringElementTrait; + +use function array_map; +use function explode; +use function implode; /** * A ComputedKeyOpenEnum element @@ -13,18 +21,40 @@ */ abstract class AbstractComputedKeyOpenEnum extends AbstractWstElement { - use URIElementTrait; + use StringElementTrait; + + + /** + * @param string[] $values + */ + public function __construct(array $values) + { + $values = array_map( + function (ComputedKeyEnum|string $v): string { + return ($v instanceof ComputedKeyEnum) ? $v->value : $v; + }, + $values, + ); + Assert::allValidURI($values, SchemaViolationException::class); + + $this->setContent(implode(' ', $values)); + } /** - * @param \SimpleSAML\WSSecurity\XML\wst\ComputedKeyEnum|string $content + * 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 function __construct(ComputedKeyEnum|string $content) + public static function fromXML(DOMElement $xml): static { - if ($content instanceof ComputedKeyEnum) { - $content = $content->value; - } + Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); - $this->setContent($content); + return new static(explode(' ', $xml->textContent)); } } diff --git a/src/XML/wst/AbstractKeyTypeOpenEnum.php b/src/XML/wst/AbstractKeyTypeOpenEnum.php index d4f60d8e..11acd9ca 100644 --- a/src/XML/wst/AbstractKeyTypeOpenEnum.php +++ b/src/XML/wst/AbstractKeyTypeOpenEnum.php @@ -4,7 +4,15 @@ namespace SimpleSAML\WSSecurity\XML\wst; -use SimpleSAML\XML\URIElementTrait; +use DOMElement; +use SimpleSAML\Assert\Assert; +use SimpleSAML\XML\Exception\InvalidDOMElementException; +use SimpleSAML\XML\Exception\SchemaViolationException; +use SimpleSAML\XML\StringElementTrait; + +use function array_map; +use function explode; +use function implode; /** * A KeyTypeOpenEnum element @@ -13,18 +21,40 @@ */ abstract class AbstractKeyTypeOpenEnum extends AbstractWstElement { - use URIElementTrait; + use StringElementTrait; + + + /** + * @param string[] $values + */ + public function __construct(array $values) + { + $values = array_map( + function (KeyTypeEnum|string $v): string { + return ($v instanceof KeyTypeEnum) ? $v->value : $v; + }, + $values, + ); + Assert::allValidURI($values, SchemaViolationException::class); + + $this->setContent(implode(' ', $values)); + } /** - * @param \SimpleSAML\WSSecurity\XML\wst\KeyTypeEnum|string $content + * 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 function __construct(KeyTypeEnum|string $content) + public static function fromXML(DOMElement $xml): static { - if ($content instanceof KeyTypeEnum) { - $content = $content->value; - } + Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); - $this->setContent($content); + return new static(explode(' ', $xml->textContent)); } } diff --git a/src/XML/wst/AbstractRequestTypeOpenEnum.php b/src/XML/wst/AbstractRequestTypeOpenEnum.php index 599988dd..fd10bcc1 100644 --- a/src/XML/wst/AbstractRequestTypeOpenEnum.php +++ b/src/XML/wst/AbstractRequestTypeOpenEnum.php @@ -4,7 +4,15 @@ namespace SimpleSAML\WSSecurity\XML\wst; -use SimpleSAML\XML\URIElementTrait; +use DOMElement; +use SimpleSAML\Assert\Assert; +use SimpleSAML\XML\Exception\InvalidDOMElementException; +use SimpleSAML\XML\Exception\SchemaViolationException; +use SimpleSAML\XML\StringElementTrait; + +use function array_map; +use function explode; +use function implode; /** * A RequestTypeOpenEnum element @@ -13,18 +21,40 @@ */ abstract class AbstractRequestTypeOpenEnum extends AbstractWstElement { - use URIElementTrait; + use StringElementTrait; + + + /** + * @param string[] $values + */ + public function __construct(array $values) + { + $values = array_map( + function (RequestTypeEnum|string $v): string { + return ($v instanceof RequestTypeEnum) ? $v->value : $v; + }, + $values, + ); + Assert::allValidURI($values, SchemaViolationException::class); + + $this->setContent(implode(' ', $values)); + } /** - * @param \SimpleSAML\WSSecurity\XML\wst\RequestTypeEnum|string $content + * 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 function __construct(RequestTypeEnum|string $content) + public static function fromXML(DOMElement $xml): static { - if ($content instanceof RequestTypeEnum) { - $content = $content->value; - } + Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); - $this->setContent($content); + return new static(explode(' ', $xml->textContent)); } } diff --git a/src/XML/wst/AbstractStatusCodeOpenEnum.php b/src/XML/wst/AbstractStatusCodeOpenEnum.php index 2bc6c536..b813a44a 100644 --- a/src/XML/wst/AbstractStatusCodeOpenEnum.php +++ b/src/XML/wst/AbstractStatusCodeOpenEnum.php @@ -4,7 +4,15 @@ namespace SimpleSAML\WSSecurity\XML\wst; -use SimpleSAML\XML\URIElementTrait; +use DOMElement; +use SimpleSAML\Assert\Assert; +use SimpleSAML\XML\Exception\InvalidDOMElementException; +use SimpleSAML\XML\Exception\SchemaViolationException; +use SimpleSAML\XML\StringElementTrait; + +use function array_map; +use function explode; +use function implode; /** * A StatusCodeOpenEnum element @@ -13,18 +21,40 @@ */ abstract class AbstractStatusCodeOpenEnum extends AbstractWstElement { - use URIElementTrait; + use StringElementTrait; + + + /** + * @param string[] $values + */ + public function __construct(array $values) + { + $values = array_map( + function (StatusCodeEnum|string $v): string { + return ($v instanceof StatusCodeEnum) ? $v->value : $v; + }, + $values, + ); + Assert::allValidURI($values, SchemaViolationException::class); + + $this->setContent(implode(' ', $values)); + } /** - * @param \SimpleSAML\WSSecurity\XML\wst\StatusCodeEnum|string $content + * 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 function __construct(StatusCodeEnum|string $content) + public static function fromXML(DOMElement $xml): static { - if ($content instanceof StatusCodeEnum) { - $content = $content->value; - } + Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); - $this->setContent($content); + return new static(explode(' ', $xml->textContent)); } } diff --git a/tests/WSSecurity/XML/wst/CodeTest.php b/tests/WSSecurity/XML/wst/CodeTest.php index 7f952822..bf02d57b 100644 --- a/tests/WSSecurity/XML/wst/CodeTest.php +++ b/tests/WSSecurity/XML/wst/CodeTest.php @@ -46,7 +46,7 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $code = new Code(StatusCodeEnum::Invalid); + $code = new Code([StatusCodeEnum::Invalid]); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/WSSecurity/XML/wst/ComputedKeyTest.php b/tests/WSSecurity/XML/wst/ComputedKeyTest.php index 4b97b8b5..a9e10f29 100644 --- a/tests/WSSecurity/XML/wst/ComputedKeyTest.php +++ b/tests/WSSecurity/XML/wst/ComputedKeyTest.php @@ -50,7 +50,7 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $computedKey = new ComputedKey(ComputedKeyEnum::PSHA1); + $computedKey = new ComputedKey([ComputedKeyEnum::PSHA1]); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/WSSecurity/XML/wst/KeyTypeTest.php b/tests/WSSecurity/XML/wst/KeyTypeTest.php index fb299252..74966982 100644 --- a/tests/WSSecurity/XML/wst/KeyTypeTest.php +++ b/tests/WSSecurity/XML/wst/KeyTypeTest.php @@ -50,7 +50,7 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $keyType = new KeyType(KeyTypeEnum::PublicKey); + $keyType = new KeyType([KeyTypeEnum::PublicKey]); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/WSSecurity/XML/wst/RequestTypeTest.php b/tests/WSSecurity/XML/wst/RequestTypeTest.php index f6903bd0..c014a909 100644 --- a/tests/WSSecurity/XML/wst/RequestTypeTest.php +++ b/tests/WSSecurity/XML/wst/RequestTypeTest.php @@ -50,7 +50,7 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $requestType = new RequestType(RequestTypeEnum::Issue); + $requestType = new RequestType([RequestTypeEnum::Issue]); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/WSSecurity/XML/wst/StatusTest.php b/tests/WSSecurity/XML/wst/StatusTest.php index e8bdf923..e9ad3864 100644 --- a/tests/WSSecurity/XML/wst/StatusTest.php +++ b/tests/WSSecurity/XML/wst/StatusTest.php @@ -52,7 +52,7 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $code = new Code(StatusCodeEnum::Invalid); + $code = new Code([StatusCodeEnum::Invalid]); $reason = new Reason('phpunit'); $status = new Status($code, $reason);