Skip to content
This repository was archived by the owner on Jan 21, 2026. It is now read-only.

Commit 59476b6

Browse files
committed
Migrate to xsd-types
1 parent 6b57bb8 commit 59476b6

79 files changed

Lines changed: 294 additions & 319 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/XML/wsse/AbstractUsernameTokenType.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static function fromXML(DOMElement $xml): static
104104

105105
$Id = null;
106106
if ($xml->hasAttributeNS(C::NS_SEC_UTIL, 'Id')) {
107-
$ID = $xml->getAttributeNS(C::NS_SEC_UTIL, 'Id');
107+
$Id = IDValue::fromString($xml->getAttributeNS(C::NS_SEC_UTIL, 'Id'));
108108
}
109109

110110
return new static(
@@ -128,7 +128,7 @@ public function toXML(?DOMElement $parent = null): DOMElement
128128

129129
$attributes = $this->getAttributesNS();
130130
if ($this->getId() !== null) {
131-
$idAttr = new XMLAttribute(C::NS_SEC_UTIL, 'wsu', 'Id', $this->getId());
131+
$idAttr = new XMLAttribute(C::NS_SEC_UTIL, 'wsu', 'Id', $this->getId()->getValue());
132132
array_unshift($attributes, $idAttr);
133133
}
134134

@@ -138,7 +138,6 @@ public function toXML(?DOMElement $parent = null): DOMElement
138138

139139
$this->getUsername()->toXML($e);
140140

141-
/** @psalm-var \SimpleSAML\XML\SerializableElementInterface $child */
142141
foreach ($this->getElements() as $child) {
143142
if (!$child->isEmptyElement()) {
144143
$child->toXML($e);

src/XML/wst_200502/AbstractComputedKeyOpenEnum.php

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,19 @@
44

55
namespace SimpleSAML\WSSecurity\XML\wst_200502;
66

7-
use DOMElement;
8-
use SimpleSAML\WSSecurity\Assert\Assert;
97
use SimpleSAML\XML\TypedTextContentTrait;
10-
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
11-
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
12-
use SimpleSAML\XMLSchema\Type\StringValue;
13-
14-
use function array_map;
15-
use function explode;
16-
use function implode;
8+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
179

1810
/**
1911
* A ComputedKeyOpenEnum element
2012
*
2113
* @package simplesamlphp/ws-security
22-
*
23-
* @phpstan-consistent-constructor
2414
*/
2515
abstract class AbstractComputedKeyOpenEnum extends AbstractWstElement
2616
{
2717
use TypedTextContentTrait;
2818

2919

3020
/** @var string */
31-
public const TEXTCONTENT_TYPE = StringValue::class;
32-
33-
34-
/**
35-
* @param (\SimpleSAML\WSSecurity\XML\wst_200502\ComputedKeyEnum|string)[] $values
36-
*/
37-
public function __construct(array $values)
38-
{
39-
$values = array_map(
40-
function (ComputedKeyEnum|string $v): string {
41-
return ($v instanceof ComputedKeyEnum) ? $v->value : $v;
42-
},
43-
$values,
44-
);
45-
Assert::allValidURI($values, SchemaViolationException::class);
46-
47-
$this->setContent(StringValue::fromString(implode(' ', $values)));
48-
}
49-
50-
51-
/**
52-
* Convert XML into a class instance
53-
*
54-
* @param \DOMElement $xml The XML element we should load
55-
* @return static
56-
*
57-
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
58-
* If the qualified name of the supplied element is wrong
59-
*/
60-
public static function fromXML(DOMElement $xml): static
61-
{
62-
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
63-
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
64-
65-
return new static(explode(' ', $xml->textContent));
66-
}
21+
public const TEXTCONTENT_TYPE = AnyURIValue::class;
6722
}

src/XML/wst_200502/AbstractKeyTypeOpenEnum.php

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,19 @@
44

55
namespace SimpleSAML\WSSecurity\XML\wst_200502;
66

7-
use DOMElement;
8-
use SimpleSAML\WSSecurity\Assert\Assert;
97
use SimpleSAML\XML\TypedTextContentTrait;
10-
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
11-
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
12-
use SimpleSAML\XMLSchema\Type\StringValue;
13-
14-
use function array_map;
15-
use function explode;
16-
use function implode;
8+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
179

1810
/**
1911
* A KeyTypeOpenEnum element
2012
*
2113
* @package simplesamlphp/ws-security
22-
*
23-
* @phpstan-consistent-constructor
2414
*/
2515
abstract class AbstractKeyTypeOpenEnum extends AbstractWstElement
2616
{
2717
use TypedTextContentTrait;
2818

2919

3020
/** @var string */
31-
public const TEXTCONTENT_TYPE = StringValue::class;
32-
33-
34-
/**
35-
* @param (\SimpleSAML\WSSecurity\XML\wst_200502\KeyTypeEnum|string)[] $values
36-
*/
37-
public function __construct(array $values)
38-
{
39-
$values = array_map(
40-
function (KeyTypeEnum|string $v): string {
41-
return ($v instanceof KeyTypeEnum) ? $v->value : $v;
42-
},
43-
$values,
44-
);
45-
Assert::allValidURI($values, SchemaViolationException::class);
46-
47-
$this->setContent(StringValue::fromString(implode(' ', $values)));
48-
}
49-
50-
51-
/**
52-
* Convert XML into a class instance
53-
*
54-
* @param \DOMElement $xml The XML element we should load
55-
* @return static
56-
*
57-
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
58-
* If the qualified name of the supplied element is wrong
59-
*/
60-
public static function fromXML(DOMElement $xml): static
61-
{
62-
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
63-
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
64-
65-
return new static(explode(' ', $xml->textContent));
66-
}
21+
public const TEXTCONTENT_TYPE = AnyURIValue::class;
6722
}

src/XML/wst_200502/AbstractRequestTypeOpenEnum.php

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,19 @@
44

55
namespace SimpleSAML\WSSecurity\XML\wst_200502;
66

7-
use DOMElement;
8-
use SimpleSAML\WSSecurity\Assert\Assert;
97
use SimpleSAML\XML\TypedTextContentTrait;
10-
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
11-
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
12-
use SimpleSAML\XMLSchema\Type\StringValue;
13-
14-
use function array_map;
15-
use function explode;
16-
use function implode;
8+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
179

1810
/**
1911
* A RequestTypeOpenEnum element
2012
*
2113
* @package simplesamlphp/ws-security
22-
*
23-
* @phpstan-consistent-constructor
2414
*/
2515
abstract class AbstractRequestTypeOpenEnum extends AbstractWstElement
2616
{
2717
use TypedTextContentTrait;
2818

2919

3020
/** @var string */
31-
public const TEXTCONTENT_TYPE = StringValue::class;
32-
33-
34-
/**
35-
* @param (\SimpleSAML\WSSecurity\XML\wst_200502\RequestTypeEnum|string)[] $values
36-
*/
37-
public function __construct(array $values)
38-
{
39-
$values = array_map(
40-
function (RequestTypeEnum|string $v): string {
41-
return ($v instanceof RequestTypeEnum) ? $v->value : $v;
42-
},
43-
$values,
44-
);
45-
Assert::allValidURI($values, SchemaViolationException::class);
46-
47-
$this->setContent(StringValue::fromString(implode(' ', $values)));
48-
}
49-
50-
51-
/**
52-
* Convert XML into a class instance
53-
*
54-
* @param \DOMElement $xml The XML element we should load
55-
* @return static
56-
*
57-
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
58-
* If the qualified name of the supplied element is wrong
59-
*/
60-
public static function fromXML(DOMElement $xml): static
61-
{
62-
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
63-
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
64-
65-
return new static(explode(' ', $xml->textContent));
66-
}
21+
public const TEXTCONTENT_TYPE = AnyURIValue::class;
6722
}

src/XML/wst_200502/AbstractStatusCodeOpenEnum.php

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,8 @@
44

55
namespace SimpleSAML\WSSecurity\XML\wst_200502;
66

7-
use DOMElement;
8-
use SimpleSAML\WSSecurity\Assert\Assert;
97
use SimpleSAML\XML\TypedTextContentTrait;
10-
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
11-
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
12-
use SimpleSAML\XMLSchema\Type\StringValue;
13-
14-
use function array_map;
15-
use function explode;
16-
use function implode;
8+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
179

1810
/**
1911
* A StatusCodeOpenEnum element
@@ -28,40 +20,5 @@ abstract class AbstractStatusCodeOpenEnum extends AbstractWstElement
2820

2921

3022
/** @var string */
31-
public const TEXTCONTENT_TYPE = StringValue::class;
32-
33-
34-
/**
35-
* @param (\SimpleSAML\WSSecurity\XML\wst_200502\StatusCodeEnum|string)[] $values
36-
*/
37-
public function __construct(array $values)
38-
{
39-
$values = array_map(
40-
function (StatusCodeEnum|string $v): string {
41-
return ($v instanceof StatusCodeEnum) ? $v->value : $v;
42-
},
43-
$values,
44-
);
45-
Assert::allValidURI($values, SchemaViolationException::class);
46-
47-
$this->setContent(StringValue::fromString(implode(' ', $values)));
48-
}
49-
50-
51-
/**
52-
* Convert XML into a class instance
53-
*
54-
* @param \DOMElement $xml The XML element we should load
55-
* @return static
56-
*
57-
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
58-
* If the qualified name of the supplied element is wrong
59-
*/
60-
public static function fromXML(DOMElement $xml): static
61-
{
62-
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
63-
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
64-
65-
return new static(explode(' ', $xml->textContent));
66-
}
23+
public const TEXTCONTENT_TYPE = AnyURIValue::class;
6724
}

src/XML/wst_200512/AbstractStatusCodeOpenEnum.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
* A StatusCodeOpenEnum element
1212
*
1313
* @package simplesamlphp/ws-security
14-
*
15-
* @phpstan-consistent-constructor
1614
*/
1715
abstract class AbstractStatusCodeOpenEnum extends AbstractWstElement
1816
{

tests/WSSecurity/XML/wsse/UsernameTokenTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use SimpleSAML\XML\DOMDocumentFactory;
1717
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
1818
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
19+
use SimpleSAML\XMLSchema\Type\StringValue;
1920

2021
use function dirname;
2122
use function strval;
@@ -55,8 +56,8 @@ public static function setUpBeforeClass(): void
5556
*/
5657
public function testMarshalling(): void
5758
{
58-
$attr1 = new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr1', 'testval1');
59-
$attr2 = new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr2', 'testval2');
59+
$attr1 = new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr1', StringValue::fromString('testval1'));
60+
$attr2 = new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr2', StringValue::fromString('testval2'));
6061
$username = new Username('johndoe@example.com', 'OtherID', [$attr2]);
6162
$child = DOMDocumentFactory::fromString(
6263
'<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">SomeChunk</ssp:Chunk>',

tests/WSSecurity/XML/wst_200502/AuthenticationTypeTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use SimpleSAML\XML\DOMDocumentFactory;
1414
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
1515
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
16+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
1617

1718
use function dirname;
1819

@@ -52,7 +53,7 @@ public static function setUpBeforeClass(): void
5253
*/
5354
public function testMarshalling(): void
5455
{
55-
$authenticationType = new AuthenticationType(C::NAMESPACE);
56+
$authenticationType = new AuthenticationType(AnyURIValue::fromString(C::NAMESPACE));
5657

5758
$this->assertEquals(
5859
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),

tests/WSSecurity/XML/wst_200502/AuthenticatorTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use SimpleSAML\XML\DOMDocumentFactory;
1717
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
1818
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
19+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
20+
use SimpleSAML\XMLSchema\Type\Base64BinaryValue;
1921

2022
use function dirname;
2123

@@ -57,9 +59,14 @@ public static function setUpBeforeClass(): void
5759
public function testMarshalling(): void
5860
{
5961
$mustUnderstand = MustUnderstandValue::fromBoolean(true);
60-
$msgId = new MessageID('uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de', [$mustUnderstand->toAttribute()]);
62+
$msgId = new MessageID(
63+
AnyURIValue::fromString('uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de'),
64+
[$mustUnderstand->toAttribute()],
65+
);
6166

62-
$combinedHash = new CombinedHash('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
67+
$combinedHash = new CombinedHash(
68+
Base64BinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='),
69+
);
6370
$authenticator = new Authenticator($combinedHash, [$msgId]);
6471

6572
$this->assertEquals(

tests/WSSecurity/XML/wst_200502/BinaryExchangeTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use SimpleSAML\XML\DOMDocumentFactory;
1616
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
1717
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
18+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
19+
use SimpleSAML\XMLSchema\Type\StringValue;
1820

1921
use function dirname;
2022

@@ -55,8 +57,13 @@ public static function setUpBeforeClass(): void
5557
*/
5658
public function testMarshalling(): void
5759
{
58-
$attr1 = new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr1', 'testval1');
59-
$binaryExchange = new BinaryExchange('phpunit', C::NAMESPACE, C::NAMESPACE, [$attr1]);
60+
$attr1 = new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr1', StringValue::fromString('testval1'));
61+
$binaryExchange = new BinaryExchange(
62+
StringValue::fromString('phpunit'),
63+
AnyURIValue::fromString(C::NAMESPACE),
64+
AnyURIValue::fromString(C::NAMESPACE),
65+
[$attr1],
66+
);
6067

6168
$this->assertEquals(
6269
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),

0 commit comments

Comments
 (0)