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

Commit a424186

Browse files
committed
Migrate to xsd-types
1 parent dff51ef commit a424186

10 files changed

Lines changed: 79 additions & 74 deletions

File tree

src/XML/wsp/AbstractOperatorContentType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
use SimpleSAML\WSSecurity\Assert\Assert;
1010
use SimpleSAML\XML\Chunk;
1111
use SimpleSAML\XML\Constants as C;
12-
use SimpleSAML\XML\Exception\InvalidDOMElementException;
1312
use SimpleSAML\XML\ExtendableElementTrait;
1413
use SimpleSAML\XML\SerializableElementInterface;
15-
use SimpleSAML\XML\XsNamespace as NS;
14+
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
15+
use SimpleSAML\XMLSchema\XML\Constants\NS;
1616

1717
/**
1818
* Class representing a wsp:OperatorContentType element.
@@ -90,7 +90,7 @@ public function isEmptyElement(): bool
9090
* @param \DOMElement $xml The XML element we should load
9191
* @return static
9292
*
93-
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
93+
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
9494
* If the qualified name of the supplied element is wrong
9595
*/
9696
public static function fromXML(DOMElement $xml): static

src/XML/wsp/All.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
namespace SimpleSAML\WSSecurity\XML\wsp;
66

7-
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
7+
use SimpleSAML\XML\SchemaValidatableElementInterface;
8+
use SimpleSAML\XML\SchemaValidatableElementTrait;
89

910
/**
1011
* Class defining the All element

src/XML/wsp/AppliesTo.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
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\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
13-
use SimpleSAML\XML\XsNamespace as NS;
11+
use SimpleSAML\XML\SchemaValidatableElementInterface;
12+
use SimpleSAML\XML\SchemaValidatableElementTrait;
13+
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
14+
use SimpleSAML\XMLSchema\XML\Constants\NS;
1415

1516
/**
1617
* Class representing a wsp:AppliesTo element.
@@ -60,7 +61,7 @@ public function isEmptyElement(): bool
6061
* @param \DOMElement $xml The XML element we should load
6162
* @return static
6263
*
63-
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
64+
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
6465
* If the qualified name of the supplied element is wrong
6566
*/
6667
public static function fromXML(DOMElement $xml): static

src/XML/wsp/ExactlyOne.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
namespace SimpleSAML\WSSecurity\XML\wsp;
66

7-
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
7+
use SimpleSAML\XML\SchemaValidatableElementInterface;
8+
use SimpleSAML\XML\SchemaValidatableElementTrait;
89

910
/**
1011
* Class defining the ExactlyOne element

src/XML/wsp/OptionalTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Trait grouping common functionality for elements that can hold an Optional attribute.
99
*
1010
* @package simplesamlphp/ws-security
11+
* @phpstan-ignore trait.unused
1112
*/
1213
trait OptionalTrait
1314
{

src/XML/wsp/Policy.php

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
use DOMElement;
88
use SimpleSAML\WSSecurity\Assert\Assert;
99
use SimpleSAML\WSSecurity\Constants as C;
10-
use SimpleSAML\XML\Attribute as XMLAttribute;
10+
use SimpleSAML\WSSecurity\XML\wsu\Type\IDValue;
1111
use SimpleSAML\XML\Chunk;
12-
use SimpleSAML\XML\Exception\InvalidDOMElementException;
13-
use SimpleSAML\XML\Exception\SchemaViolationException;
1412
use SimpleSAML\XML\ExtendableAttributesTrait;
15-
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
16-
use SimpleSAML\XML\XsNamespace as NS;
13+
use SimpleSAML\XML\SchemaValidatableElementInterface;
14+
use SimpleSAML\XML\SchemaValidatableElementTrait;
15+
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
16+
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
17+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
18+
use SimpleSAML\XMLSchema\XML\Constants\NS;
1719

1820
/**
1921
* Class defining the Policy element
@@ -32,46 +34,41 @@ final class Policy extends AbstractOperatorContentType implements SchemaValidata
3234
/**
3335
* Initialize a wsp:Policy
3436
*
35-
* @param string|null $Name
36-
* @param \SimpleSAML\XML\Attribute|null $Id
3737
* @param (\SimpleSAML\WSSecurity\XML\wsp\All|
3838
* \SimpleSAML\WSSecurity\XML\wsp\ExactlyOne|
3939
* \SimpleSAML\WSSecurity\XML\wsp\Policy|
4040
* \SimpleSAML\WSSecurity\XML\wsp\PolicyReference)[] $operatorContent
41-
* @param \SimpleSAML\XML\Chunk[] $children
41+
* @param \SimpleSAML\XML\SerializableElementInterface[] $children
42+
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue|null $Name
43+
* @param \SimpleSAML\WSSecurity\XML\wsu\Type\IDValue|null $Id
4244
* @param \SimpleSAML\XML\Attribute[] $namespacedAttributes
4345
*/
4446
public function __construct(
45-
protected ?string $Name = null,
46-
protected ?XMLAttribute $Id = null,
4747
array $operatorContent = [],
4848
array $children = [],
49+
protected ?AnyURIValue $Name = null,
50+
protected ?IDValue $Id = null,
4951
array $namespacedAttributes = [],
5052
) {
51-
Assert::nullOrValidURI($Name, SchemaViolationException::class);
52-
if ($Id !== null) {
53-
Assert::validNCName($Id->getAttrValue(), SchemaViolationException::class);
54-
}
55-
5653
$this->setAttributesNS($namespacedAttributes);
5754

5855
parent::__construct($operatorContent, $children);
5956
}
6057

6158

6259
/**
63-
* @return \SimpleSAML\XML\Attribute|null
60+
* @return \SimpleSAML\WSSecurity\XML\wsu\Type\IDValue|null
6461
*/
65-
public function getId(): ?XMLAttribute
62+
public function getId(): ?IDValue
6663
{
6764
return $this->Id;
6865
}
6966

7067

7168
/**
72-
* @return string|null
69+
* @return \SimpleSAML\XMLSchema\Type\AnyURIValue|null
7370
*/
74-
public function getName(): ?string
71+
public function getName(): ?AnyURIValue
7572
{
7673
return $this->Name;
7774
}
@@ -97,7 +94,7 @@ final public function isEmptyElement(): bool
9794
* @param \DOMElement $xml The XML element we should load
9895
* @return static
9996
*
100-
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
97+
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
10198
* If the qualified name of the supplied element is wrong
10299
*/
103100
#[\Override]
@@ -108,7 +105,7 @@ public static function fromXML(DOMElement $xml): static
108105

109106
$Id = null;
110107
if ($xml->hasAttributeNS(C::NS_SEC_UTIL, 'Id')) {
111-
$Id = new XMLAttribute(C::NS_SEC_UTIL, 'wsu', 'Id', $xml->getAttributeNS(C::NS_SEC_UTIL, 'Id'));
108+
$Id = IDValue::fromString($xml->getAttributeNS(C::NS_SEC_UTIL, 'Id'));
112109
}
113110

114111
$namespacedAttributes = self::getAttributesNSFromXML($xml);
@@ -145,10 +142,10 @@ public static function fromXML(DOMElement $xml): static
145142
}
146143

147144
return new static(
148-
self::getOptionalAttribute($xml, 'Name', null),
149-
$Id,
150145
$operatorContent,
151146
$children,
147+
self::getOptionalAttribute($xml, 'Name', AnyURIValue::class, null),
148+
$Id,
152149
$namespacedAttributes,
153150
);
154151
}
@@ -165,10 +162,10 @@ public function toXML(?DOMElement $parent = null): DOMElement
165162
$e = parent::toXML($parent);
166163

167164
if ($this->getName() !== null) {
168-
$e->setAttribute('Name', $this->getName());
165+
$e->setAttribute('Name', $this->getName()->getValue());
169166
}
170167

171-
$this->getId()?->toXML($e);
168+
$this->getId()?->toAttribute()->toXML($e);
172169

173170
foreach ($this->getAttributesNS() as $attr) {
174171
$attr->toXML($e);

src/XML/wsp/PolicyAttachment.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
use SimpleSAML\WSSecurity\XML\wsp\AppliesTo;
1010
use SimpleSAML\WSSecurity\XML\wsp\Policy;
1111
use SimpleSAML\WSSecurity\XML\wsp\PolicyReference;
12-
use SimpleSAML\XML\Exception\InvalidDOMElementException;
13-
use SimpleSAML\XML\Exception\MissingElementException;
14-
use SimpleSAML\XML\Exception\TooManyElementsException;
1512
use SimpleSAML\XML\ExtendableAttributesTrait;
1613
use SimpleSAML\XML\ExtendableElementTrait;
17-
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
18-
use SimpleSAML\XML\XsNamespace as NS;
14+
use SimpleSAML\XML\SchemaValidatableElementInterface;
15+
use SimpleSAML\XML\SchemaValidatableElementTrait;
16+
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
17+
use SimpleSAML\XMLSchema\Exception\MissingElementException;
18+
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
19+
use SimpleSAML\XMLSchema\XML\Constants\NS;
1920

2021
use function array_merge;
2122

@@ -84,7 +85,7 @@ public function getPolicies(): array
8485
* @param \DOMElement $xml The XML element we should load
8586
* @return static
8687
*
87-
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
88+
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
8889
* If the qualified name of the supplied element is wrong
8990
*/
9091
public static function fromXML(DOMElement $xml): static

src/XML/wsp/PolicyReference.php

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

77
use DOMElement;
88
use SimpleSAML\WSSecurity\Assert\Assert;
9-
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10-
use SimpleSAML\XML\Exception\SchemaViolationException;
119
use SimpleSAML\XML\ExtendableAttributesTrait;
12-
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
13-
use SimpleSAML\XML\XsNamespace as NS;
10+
use SimpleSAML\XML\SchemaValidatableElementInterface;
11+
use SimpleSAML\XML\SchemaValidatableElementTrait;
12+
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
13+
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
14+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
15+
use SimpleSAML\XMLSchema\Type\Base64BinaryValue;
16+
use SimpleSAML\XMLSchema\XML\Constants\NS;
1417

1518
use function str_replace;
1619

@@ -31,47 +34,43 @@ final class PolicyReference extends AbstractWspElement implements SchemaValidata
3134
/**
3235
* Initialize a wsp:PolicyReference
3336
*
34-
* @param string $URI
35-
* @param string|null $Digest
36-
* @param string $DigestAlgorithm
37+
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue $URI
38+
* @param \SimpleSAML\XMLSchema\Type\Base64BinaryValue|null $Digest
39+
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue $DigestAlgorithm
3740
* @param \SimpleSAML\XML\Attribute[] $namespacedAttributes
3841
*/
3942
public function __construct(
40-
protected string $URI,
41-
protected ?string $Digest = null,
42-
protected ?string $DigestAlgorithm = 'http://schemas.xmlsoap.org/ws/2004/09/policy/Sha1Exc',
43+
protected AnyURIValue $URI,
44+
protected ?Base64BinaryValue $Digest = null,
45+
protected ?AnyURIValue $DigestAlgorithm = null,
4346
array $namespacedAttributes = [],
4447
) {
45-
Assert::validURI($URI, SchemaViolationException::class);
46-
Assert::nullOrValidBase64($Digest, SchemaViolationException::class);
47-
Assert::nullOrValidURI($DigestAlgorithm, SchemaViolationException::class);
48-
4948
$this->setAttributesNS($namespacedAttributes);
5049
}
5150

5251

5352
/**
54-
* @return string
53+
* @return \SimpleSAML\XMLSchema\Type\AnyURIValue
5554
*/
56-
public function getURI(): string
55+
public function getURI(): AnyURIValue
5756
{
5857
return $this->URI;
5958
}
6059

6160

6261
/**
63-
* @return string|null
62+
* @return \SimpleSAML\XMLSchema\Type\Base64BinaryValue|null
6463
*/
65-
public function getDigest(): ?string
64+
public function getDigest(): ?Base64BinaryValue
6665
{
67-
return $this->Digest ? str_replace(["\f", "\r", "\n", "\t", "\v", ' '], '', $this->Digest) : null;
66+
return $this->Digest;
6867
}
6968

7069

7170
/**
72-
* @return string|null
71+
* @return \SimpleSAML\XMLSchema\Type\AnyURIValue|null
7372
*/
74-
public function getDigestAlgorithm(): ?string
73+
public function getDigestAlgorithm(): ?AnyURIValue
7574
{
7675
return $this->DigestAlgorithm;
7776
}
@@ -83,7 +82,7 @@ public function getDigestAlgorithm(): ?string
8382
* @param \DOMElement $xml The XML element we should load
8483
* @return static
8584
*
86-
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
85+
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
8786
* If the qualified name of the supplied element is wrong
8887
*/
8988
public static function fromXML(DOMElement $xml): static
@@ -108,9 +107,9 @@ public static function fromXML(DOMElement $xml): static
108107
}
109108

110109
return new static(
111-
self::getAttribute($xml, 'URI'),
112-
self::getOptionalAttribute($xml, 'Digest', null),
113-
self::getOptionalAttribute($xml, 'DigestAlgorithm', null),
110+
self::getAttribute($xml, 'URI', AnyURIValue::class),
111+
self::getOptionalAttribute($xml, 'Digest', Base64BinaryValue::class, null),
112+
self::getOptionalAttribute($xml, 'DigestAlgorithm', AnyURIValue::class, null),
114113
$namespacedAttributes,
115114
);
116115
}
@@ -125,14 +124,14 @@ public static function fromXML(DOMElement $xml): static
125124
public function toXML(?DOMElement $parent = null): DOMElement
126125
{
127126
$e = $this->instantiateParentElement($parent);
128-
$e->setAttribute('URI', $this->getURI());
127+
$e->setAttribute('URI', $this->getURI()->getValue());
129128

130129
if ($this->getDigest() !== null) {
131-
$e->setAttribute('Digest', $this->getDigest());
130+
$e->setAttribute('Digest', $this->getDigest()->getValue());
132131
}
133132

134133
if ($this->getDigestAlgorithm() !== null) {
135-
$e->setAttribute('DigestAlgorithm', $this->getDigestAlgorithm());
134+
$e->setAttribute('DigestAlgorithm', $this->getDigestAlgorithm()->getValue());
136135
}
137136

138137
foreach ($this->getAttributesNS() as $attr) {

src/XML/wsp/PolicyURIsTrait.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,29 @@
55
namespace SimpleSAML\WSSecurity\XML\wsp;
66

77
use SimpleSAML\WSSecurity\Assert\Assert;
8+
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
9+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
810

911
/**
1012
* Trait grouping common functionality for elements that can hold a PolicyURIs attribute.
1113
*
1214
* @package simplesamlphp/ws-security
15+
* @phpstan-ignore trait.unused
1316
*/
1417
trait PolicyURIsTrait
1518
{
1619
/**
1720
* The PolicyURIs.
1821
*
19-
* @var string[]
22+
* @var \SimpleSAML\XMLSchema\Type\AnyURIValue[]
2023
*/
2124
protected array $PolicyURIs;
2225

2326

2427
/**
2528
* Collect the value of the PolicyURIs-property
2629
*
27-
* @return array
30+
* @return \SimpleSAML\XMLSchema\Type\AnyURIValue[]
2831
*/
2932
public function getPolicyURIs(): array
3033
{
@@ -35,11 +38,11 @@ public function getPolicyURIs(): array
3538
/**
3639
* Set the value of the PolicyURIs-property
3740
*
38-
* @param array $PolicyURIs
41+
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue[] $PolicyURIs
3942
*/
4043
protected function setPolicyURIs(array $PolicyURIs): void
4144
{
42-
Assert::allValidURI($PolicyURIs);
45+
Assert::allIsInstanceOf($PolicyURIs, AnyURIValue::class, SchemaViolationException::class);
4346
$this->PolicyURIs = $PolicyURIs;
4447
}
4548
}

0 commit comments

Comments
 (0)