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

Commit df3e7c5

Browse files
committed
Migrate to xsd-types
1 parent dfeb5a8 commit df3e7c5

40 files changed

Lines changed: 169 additions & 154 deletions

src/XML/ReferenceIdentifierTrait.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,33 @@
44

55
namespace SimpleSAML\WSSecurity\XML;
66

7-
use SimpleSAML\WSSecurity\Assert\Assert;
8-
use SimpleSAML\XML\Exception\SchemaViolationException;
7+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
98

109
/**
1110
* @package simplesamlphp/ws-security
11+
*
12+
* @phpstan-ignore trait.unused
1213
*/
1314
trait ReferenceIdentifierTrait
1415
{
15-
/** @var string */
16-
protected string $refId;
16+
/** @var \SimpleSAML\XMLSchema\Type\AnyURIValue */
17+
protected AnyURIValue $refId;
1718

1819

1920
/**
20-
* @return string
21+
* @return \SimpleSAML\XMLSchema\Type\AnyURIValue
2122
*/
22-
public function getRefId(): string
23+
public function getRefId(): AnyURIValue
2324
{
2425
return $this->refId;
2526
}
2627

2728

2829
/**
29-
* @param string $refId
30+
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue $refId
3031
*/
31-
private function setRefId(string $refId): void
32+
private function setRefId(AnyURIValue $refId): void
3233
{
33-
Assert::validURI($refId, SchemaViolationException::class);
3434
$this->refId = $refId;
3535
}
3636
}

src/XML/auth/AbstractClaimType.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use SimpleSAML\WSSecurity\XML\auth\EncryptedValue;
1414
use SimpleSAML\WSSecurity\XML\auth\StructuredValue;
1515
use SimpleSAML\WSSecurity\XML\auth\Value;
16+
use SimpleSAML\XML\Chunk;
1617
use SimpleSAML\XML\ExtendableAttributesTrait;
1718
use SimpleSAML\XML\ExtendableElementTrait;
1819
use SimpleSAML\XML\SerializableElementInterface;
@@ -22,7 +23,6 @@
2223
use SimpleSAML\XMLSchema\Type\BooleanValue;
2324
use SimpleSAML\XMLSchema\XML\Constants\NS;
2425

25-
use function array_filter;
2626
use function array_merge;
2727
use function array_pop;
2828
use function var_export;
@@ -78,8 +78,8 @@ final public function __construct(
7878
$value instanceof StructuredValue ||
7979
$value instanceof EncryptedValue)
8080
) {
81-
/** @psalm-var \SimpleSAML\XML\AbstractElement|\SimpleSAML\XML\Chunk $value */
82-
Assert::notSame($value->getNamespaceURI(), static::NS);
81+
/** @var \SimpleSAML\XML\Chunk|\SimpleSAML\XML\AbstractElement $value */
82+
Assert::notSame($value instanceof Chunk ? $value->getNamespaceURI() : $value::getNamespaceURI(), static::NS);
8383
}
8484
$this->setAttributesNS($namespacedAttributes);
8585
}
@@ -187,13 +187,13 @@ public static function fromXML(DOMElement $xml): static
187187
$constrainedValue = ConstrainedValue::getChildrenOfClass($xml);
188188
$otherValue = self::getChildElementsFromXML($xml);
189189

190-
$value = array_filter(array_merge(
190+
$value = array_merge(
191191
$simpleValue,
192192
$structuredValue,
193193
$encryptedValue,
194194
$constrainedValue,
195195
$otherValue,
196-
));
196+
);
197197
Assert::maxCount($value, 1, TooManyElementsException::class);
198198

199199
return new static(

src/XML/auth/AbstractConstrainedValueType.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use SimpleSAML\XMLSchema\Type\BooleanValue;
1414
use SimpleSAML\XMLSchema\XML\Constants\NS;
1515

16-
use function array_filter;
1716
use function array_merge;
1817
use function array_pop;
1918
use function var_export;
@@ -104,14 +103,14 @@ public static function fromXML(DOMElement $xml): static
104103
$valueInRangen = ValueInRangen::getChildrenOfClass($xml);
105104
$valueOneOf = ValueOneOf::getChildrenOfClass($xml);
106105

107-
$value = array_filter(array_merge(
106+
$value = array_merge(
108107
$valueLessThan,
109108
$valueLessThanOrEqual,
110109
$valueGreaterThan,
111110
$valueGreaterThanOrEqual,
112111
$valueInRangen,
113112
$valueOneOf,
114-
));
113+
);
115114
Assert::minCount($value, 1, MissingElementException::class);
116115
Assert::maxCount($value, 1, TooManyElementsException::class);
117116

src/XML/sp_200507/AbstractEmptyType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use DOMElement;
88
use SimpleSAML\WSSecurity\Assert\Assert;
9-
use SimpleSAML\XML\Exception\InvalidDOMElementException;
9+
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
1010

1111
use function sprintf;
1212

@@ -33,7 +33,7 @@ final public function __construct()
3333
* @param \DOMElement $xml The XML element we should load.
3434
* @return static
3535
*
36-
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
36+
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
3737
* if the qualified name of the supplied element is wrong
3838
*/
3939
public static function fromXML(DOMElement $xml): static

src/XML/sp_200507/AbstractHeaderType.php

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
use DOMElement;
88
use SimpleSAML\WSSecurity\Assert\Assert;
9-
use SimpleSAML\XML\Exception\InvalidDOMElementException;
109
use SimpleSAML\XML\ExtendableAttributesTrait;
11-
use SimpleSAML\XML\XsNamespace as NS;
10+
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
11+
use SimpleSAML\XMLSchema\XML\Constants\NS;
12+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
13+
use SimpleSAML\XMLSchema\Type\QNameValue;
1214

1315
use function sprintf;
1416

@@ -28,28 +30,25 @@ abstract class AbstractHeaderType extends AbstractSpElement
2830
/**
2931
* AbstractHeaderType constructor.
3032
*
31-
* @param string $namespace
32-
* @param string|null $name
33+
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue $namespace
34+
* @param \SimpleSAML\XMLSchema\Type\QNameValue|null $name
3335
* @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
3436
*/
3537
final public function __construct(
36-
protected string $namespace,
37-
protected ?string $name = null,
38+
protected AnyURIValue $namespace,
39+
protected ?QNameValue $name = null,
3840
array $namespacedAttributes = [],
3941
) {
40-
Assert::validURI($namespace);
41-
Assert::nullOrValidQName($name);
42-
4342
$this->setAttributesNS($namespacedAttributes);
4443
}
4544

4645

4746
/**
4847
* Collect the value of the Name property.
4948
*
50-
* @return string|null
49+
* @return \SimpleSAML\XMLSchema\Type\QNameValue|null
5150
*/
52-
public function getName(): ?string
51+
public function getName(): ?QNameValue
5352
{
5453
return $this->name;
5554
}
@@ -58,9 +57,9 @@ public function getName(): ?string
5857
/**
5958
* Collect the value of the Namespace property.
6059
*
61-
* @return string
60+
* @return \SimpleSAML\XMLSchema\Type\AnyURIValue
6261
*/
63-
public function getNamespace(): string
62+
public function getNamespace(): AnyURIValue
6463
{
6564
return $this->namespace;
6665
}
@@ -74,7 +73,7 @@ public function getNamespace(): string
7473
* @param \DOMElement $xml The XML element we should load.
7574
* @return static
7675
*
77-
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
76+
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
7877
* if the qualified name of the supplied element is wrong
7978
*/
8079
public static function fromXML(DOMElement $xml): static
@@ -97,8 +96,8 @@ public static function fromXML(DOMElement $xml): static
9796
}
9897

9998
return new static(
100-
self::getAttribute($xml, 'Namespace'),
101-
self::getOptionalAttribute($xml, 'Name', null),
99+
self::getAttribute($xml, 'Namespace', AnyURIValue::class),
100+
self::getOptionalAttribute($xml, 'Name', QNameValue::class, null),
102101
$namespacedAttributes,
103102
);
104103
}
@@ -115,10 +114,10 @@ public function toXML(?DOMElement $parent = null): DOMElement
115114
$e = $this->instantiateParentElement($parent);
116115

117116
if ($this->getName() !== null) {
118-
$e->setAttribute('Name', $this->getName());
117+
$e->setAttribute('Name', $this->getName()->getValue());
119118
}
120119

121-
$e->setAttribute('Namespace', $this->getNamespace());
120+
$e->setAttribute('Namespace', $this->getNamespace()->getValue());
122121

123122
foreach ($this->getAttributesNS() as $attr) {
124123
$attr->toXML($e);

src/XML/sp_200507/AbstractHttpsTokenType.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
use DOMElement;
88
use SimpleSAML\WSSecurity\Assert\Assert;
9-
use SimpleSAML\XML\Exception\InvalidDOMElementException;
109
use SimpleSAML\XML\ExtendableAttributesTrait;
1110
use SimpleSAML\XML\ExtendableElementTrait;
12-
use SimpleSAML\XML\XsNamespace as NS;
11+
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12+
use SimpleSAML\XMLSchema\Type\BooleanValue;
13+
use SimpleSAML\XMLSchema\XML\Constants\NS;
1314

1415
use function sprintf;
1516

@@ -38,12 +39,12 @@ abstract class AbstractHttpsTokenType extends AbstractSpElement
3839
/**
3940
* HttpsTokenType constructor.
4041
*
41-
* @param bool $requireClientCertificate
42+
* @param \SimpleSAML\XMLSchema\Type\BooleanValue $requireClientCertificate
4243
* @param array<\SimpleSAML\XML\SerializableElementInterface> $elts
4344
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
4445
*/
4546
final public function __construct(
46-
protected bool $requireClientCertificate,
47+
protected BooleanValue $requireClientCertificate,
4748
array $elts = [],
4849
array $namespacedAttributes = [],
4950
) {
@@ -54,8 +55,10 @@ final public function __construct(
5455

5556
/**
5657
* Get the value of the RequireClientCertificate-attribute
58+
*
59+
* @return \SimpleSAML\XMLSchema\Type\BooleanValue
5760
*/
58-
public function getRequireClientCertificate(): bool
61+
public function getRequireClientCertificate(): BooleanValue
5962
{
6063
return $this->requireClientCertificate;
6164
}
@@ -67,7 +70,7 @@ public function getRequireClientCertificate(): bool
6770
* @param \DOMElement $xml The XML element we should load.
6871
* @return static
6972
*
70-
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
73+
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
7174
* if the qualified name of the supplied element is wrong
7275
*/
7376
public static function fromXML(DOMElement $xml): static
@@ -81,7 +84,7 @@ public static function fromXML(DOMElement $xml): static
8184
);
8285

8386
return new static(
84-
self::getBooleanAttribute($xml, 'RequireClientCertificate'),
87+
self::getAttribute($xml, 'RequireClientCertificate', BooleanValue::class),
8588
self::getChildElementsFromXML($xml),
8689
self::getAttributesNSFromXML($xml),
8790
);
@@ -98,7 +101,10 @@ public function toXML(?DOMElement $parent = null): DOMElement
98101
{
99102
$e = $this->instantiateParentElement($parent);
100103

101-
$e->setAttribute('RequireClientCertificate', $this->getRequireClientCertificate() ? 'true' : 'false');
104+
$e->setAttribute(
105+
'RequireClientCertificate',
106+
$this->getRequireClientCertificate()->toBoolean() ? 'true' : 'false',
107+
);
102108

103109
foreach ($this->getElements() as $elt) {
104110
$elt->toXML($e);

src/XML/sp_200507/AbstractIssuedTokenType.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
use DOMElement;
88
use SimpleSAML\WSSecurity\Assert\Assert;
9-
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10-
use SimpleSAML\XML\Exception\MissingElementException;
11-
use SimpleSAML\XML\Exception\TooManyElementsException;
129
use SimpleSAML\XML\ExtendableAttributesTrait;
1310
use SimpleSAML\XML\ExtendableElementTrait;
14-
use SimpleSAML\XML\XsNamespace as NS;
11+
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12+
use SimpleSAML\XMLSchema\Exception\MissingElementException;
13+
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
14+
use SimpleSAML\XMLSchema\Type\StringValue;
15+
use SimpleSAML\XMLSchema\XML\Constants\NS;
1516
use ValueError;
1617

1718
use function array_pop;
@@ -93,7 +94,7 @@ public function getRequestSecurityTokenTemplate(): RequestSecurityTokenTemplate
9394
* @param \DOMElement $xml The XML element we should load.
9495
* @return static
9596
*
96-
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
97+
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
9798
* if the qualified name of the supplied element is wrong
9899
*/
99100
public static function fromXML(DOMElement $xml): static
@@ -112,9 +113,9 @@ public static function fromXML(DOMElement $xml): static
112113
Assert::minCount($requestSecurityTokenTemplate, 1, MissingElementException::class);
113114
Assert::maxCount($requestSecurityTokenTemplate, 1, TooManyElementsException::class);
114115

115-
$includeToken = self::getOptionalAttribute($xml, 'IncludeToken', null);
116+
$includeToken = self::getOptionalAttribute($xml, 'IncludeToken', StringValue::class, null);
116117
try {
117-
$includeToken = IncludeToken::from($includeToken);
118+
$includeToken = IncludeToken::from($includeToken->getValue());
118119
} catch (ValueError) {
119120
}
120121

src/XML/sp_200507/AbstractNestedPolicyType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
use DOMElement;
88
use SimpleSAML\WSSecurity\Assert\Assert;
9-
use SimpleSAML\XML\Exception\InvalidDOMElementException;
109
use SimpleSAML\XML\ExtendableAttributesTrait;
1110
use SimpleSAML\XML\ExtendableElementTrait;
12-
use SimpleSAML\XML\XsNamespace as NS;
11+
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12+
use SimpleSAML\XMLSchema\XML\Constants\NS;
1313

1414
/**
1515
* Class representing sp:NestedPolicyType
@@ -49,7 +49,7 @@ final public function __construct(
4949
* @param \DOMElement $xml The XML element we should load
5050
* @return static
5151
*
52-
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
52+
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
5353
* if the qualified name of the supplied element is wrong
5454
*/
5555
public static function fromXML(DOMElement $xml): static

src/XML/sp_200507/AbstractQNameAssertionType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
use DOMElement;
88
use SimpleSAML\WSSecurity\Assert\Assert;
9-
use SimpleSAML\XML\Exception\InvalidDOMElementException;
9+
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
1010
use SimpleSAML\XML\ExtendableAttributesTrait;
11-
use SimpleSAML\XML\XsNamespace as NS;
11+
use SimpleSAML\XMLSchema\XML\Constants\NS;
1212

1313
use function sprintf;
1414

@@ -45,7 +45,7 @@ final public function __construct(
4545
* @param \DOMElement $xml The XML element we should load.
4646
* @return static
4747
*
48-
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
48+
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
4949
* if the qualified name of the supplied element is wrong
5050
*/
5151
public static function fromXML(DOMElement $xml): static

0 commit comments

Comments
 (0)