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

Commit 3fd7bc7

Browse files
committed
Add option-flag to XPath utility
1 parent da2e278 commit 3fd7bc7

14 files changed

+97
-105
lines changed

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
"ext-dom": "*",
1515
"ext-spl": "*",
1616

17-
"simplesamlphp/assert": "~1.9.1",
17+
"simplesamlphp/assert": "~1.9",
1818
"simplesamlphp/saml2": "dev-feature/xsd-types",
19-
"simplesamlphp/xml-common": "~2.2.0",
20-
"simplesamlphp/xml-security": "~2.0.5",
21-
"simplesamlphp/xml-soap": "~2.0.5"
19+
"simplesamlphp/xml-common": "~2.3",
20+
"simplesamlphp/xml-security": "~2.0",
21+
"simplesamlphp/xml-soap": "~2.0"
2222
},
2323
"require-dev": {
24-
"simplesamlphp/simplesamlphp-test-framework": "~1.10.3"
24+
"simplesamlphp/simplesamlphp-test-framework": "~1.10"
2525
},
2626
"autoload": {
2727
"psr-4": {

src/Utils/XPath.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ class XPath extends \SimpleSAML\XMLSecurity\Utils\XPath
1919
* Get a DOMXPath object that can be used to search for WS Security elements.
2020
*
2121
* @param \DOMNode $node The document to associate to the DOMXPath object.
22+
* @param bool $autoregister Whether to auto-register all namespaces used in the document
2223
*
2324
* @return \DOMXPath A DOMXPath object ready to use in the given document, with several
2425
* ws-related namespaces already registered.
2526
*/
26-
public static function getXPath(DOMNode $node): DOMXPath
27+
public static function getXPath(DOMNode $node, bool $autoregister = false): DOMXPath
2728
{
28-
$xp = parent::getXPath($node);
29+
$xp = parent::getXPath($node, $autoregister);
2930

3031
$xp->registerNamespace('wsa', C::NS_ADDR_200508);
3132
$xp->registerNamespace('wsa', C::NS_ADDR_200408);

src/XML/sp_200507/XPath.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
use DOMXPath;
99
use SimpleSAML\WSSecurity\Assert\Assert;
1010
use SimpleSAML\XML\DOMDocumentFactory;
11-
use SimpleSAML\XML\StringElementTrait;
11+
use SimpleSAML\XML\TypedTextContentTrait;
12+
use SimpleSAML\XMLSchema\Type\StringValue;
1213

1314
/**
1415
* An XPath element
@@ -17,19 +18,10 @@
1718
*/
1819
final class XPath extends AbstractSpElement
1920
{
20-
use StringElementTrait;
21+
use TypedTextContentTrait;
2122

22-
23-
/**
24-
* Initialize an XPath.
25-
*
26-
* @param string $content
27-
*/
28-
public function __construct(
29-
string $content,
30-
) {
31-
$this->setContent($content);
32-
}
23+
/** @var string */
24+
public const TEXTCONTENT_TYPE = StringValue::class;
3325

3426

3527
/**

src/XML/wst_200512/AbstractBinaryExchangeType.php

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
use SimpleSAML\XML\Exception\InvalidDOMElementException;
1010
use SimpleSAML\XML\Exception\SchemaViolationException;
1111
use SimpleSAML\XML\ExtendableAttributesTrait;
12-
use SimpleSAML\XML\StringElementTrait;
12+
use SimpleSAML\XML\TypedTextContentTrait;
1313
use SimpleSAML\XML\XsNamespace as NS;
14+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
15+
use SimpleSAML\XMLSchema\Type\StringValue;
1416

1517
/**
1618
* A BinaryExchangeType element
@@ -20,27 +22,28 @@
2022
abstract class AbstractBinaryExchangeType extends AbstractWstElement
2123
{
2224
use ExtendableAttributesTrait;
23-
use StringElementTrait;
25+
use TypedTextContentTrait;
26+
27+
28+
/** @var string */
29+
public const TEXTCONTENT_TYPE = StringValue::class;
2430

2531
/** The namespace-attribute for the xs:anyAttribute element */
2632
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
2733

2834

2935
/**
30-
* @param string $content
31-
* @param string $valueType
32-
* @param string $encodingType
36+
* @param \SimpleSAML\XMLSchema\Type\StringValue $content
37+
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue $valueType
38+
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue $encodingType
3339
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
3440
*/
3541
final public function __construct(
36-
string $content,
37-
protected string $valueType,
38-
protected string $encodingType,
42+
StringValue $content,
43+
protected AnyURIValue $valueType,
44+
protected AnyURIValue $encodingType,
3945
array $namespacedAttributes,
4046
) {
41-
Assert::validURI($valueType, SchemaViolationException::class);
42-
Assert::validURI($encodingType, SchemaViolationException::class);
43-
4447
$this->setContent($content);
4548
$this->setAttributesNS($namespacedAttributes);
4649
}
@@ -49,9 +52,9 @@ final public function __construct(
4952
/**
5053
* Get the valueType property.
5154
*
52-
* @return string
55+
* @return \SimpleSAML\XMLSchema\Type\AnyURIValue
5356
*/
54-
public function getValueType(): string
57+
public function getValueType(): AnyURIValue
5558
{
5659
return $this->valueType;
5760
}
@@ -60,9 +63,9 @@ public function getValueType(): string
6063
/**
6164
* Get the valueType property.
6265
*
63-
* @return string
66+
* @return \SimpleSAML\XMLSchema\Type\AnyURIValue
6467
*/
65-
public function getEncodingType(): string
68+
public function getEncodingType(): AnyURIValue
6669
{
6770
return $this->encodingType;
6871
}
@@ -83,9 +86,9 @@ public static function fromXML(DOMElement $xml): static
8386
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
8487

8588
return new static(
86-
$xml->textContent,
87-
self::getAttribute($xml, 'ValueType'),
88-
self::getAttribute($xml, 'EncodingType'),
89+
StringValue::fromString($xml->textContent),
90+
self::getAttribute($xml, 'ValueType', AnyURIValue::class),
91+
self::getAttribute($xml, 'EncodingType', AnyURIValue::class),
8992
self::getAttributesNSFromXML($xml),
9093
);
9194
}
@@ -100,10 +103,10 @@ public static function fromXML(DOMElement $xml): static
100103
public function toXML(?DOMElement $parent = null): DOMElement
101104
{
102105
$e = $this->instantiateParentElement($parent);
103-
$e->textContent = $this->getContent();
106+
$e->textContent = $this->getContent()->getValue();
104107

105-
$e->setAttribute('ValueType', $this->getValueType());
106-
$e->setAttribute('EncodingType', $this->getEncodingType());
108+
$e->setAttribute('ValueType', $this->getValueType()->getValue());
109+
$e->setAttribute('EncodingType', $this->getEncodingType()->getValue());
107110

108111
foreach ($this->getAttributesNS() as $attr) {
109112
$attr->toXML($e);

src/XML/wst_200512/AbstractBinarySecretType.php

Lines changed: 12 additions & 6 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\Base64ElementTrait;
109
use SimpleSAML\XML\Exception\InvalidDOMElementException;
1110
use SimpleSAML\XML\Exception\SchemaViolationException;
1211
use SimpleSAML\XML\ExtendableAttributesTrait;
12+
use SimpleSAML\XML\TypedTextContentTrait;
1313
use SimpleSAML\XML\XsNamespace as NS;
14+
use SimpleSAML\XMLSchema\Base64BinaryValue;
1415

1516
use function array_map;
1617
use function explode;
@@ -23,23 +24,28 @@
2324
*/
2425
abstract class AbstractBinarySecretType extends AbstractWstElement
2526
{
26-
use Base64ElementTrait;
2727
use ExtendableAttributesTrait;
28+
use TypedTextContentTrait;
29+
30+
31+
/** @var string */
32+
public const TEXTCONTENT_TYPE = Base64BinaryValue::class;
2833

2934
/** @var string|\SimpleSAML\XML\XsNamespace */
3035
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
3136

37+
3238
/** @var string[]|null */
3339
protected ?array $Type;
3440

3541

3642
/**
37-
* @param string $content
43+
* @param \SimpleSAML\XMLSchema\Type\Base64BinaryValue $content
3844
* @param (\SimpleSAML\WSSecurity\XML\wst_200512\BinarySecretTypeEnum|string)[]|null $Type
3945
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
4046
*/
4147
final public function __construct(
42-
string $content,
48+
Base64BinaryValue $content,
4349
?array $Type = null,
4450
array $namespacedAttributes = [],
4551
) {
@@ -85,7 +91,7 @@ public static function fromXML(DOMElement $xml): static
8591
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
8692

8793
return new static(
88-
$xml->textContent,
94+
Base64BinaryValue::fromString($xml->textContent),
8995
explode(' ', self::getAttribute($xml, 'Type')),
9096
self::getAttributesNSFromXML($xml),
9197
);
@@ -101,7 +107,7 @@ public static function fromXML(DOMElement $xml): static
101107
public function toXML(?DOMElement $parent = null): DOMElement
102108
{
103109
$e = $this->instantiateParentElement($parent);
104-
$e->textContent = $this->getContent();
110+
$e->textContent = $this->getContent()->getValue();
105111

106112
if ($this->getType() !== null) {
107113
$e->setAttribute('Type', implode(' ', $this->getType()));

src/XML/wst_200512/AbstractComputedKeyOpenEnum.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
use SimpleSAML\WSSecurity\Assert\Assert;
99
use SimpleSAML\XML\Exception\InvalidDOMElementException;
1010
use SimpleSAML\XML\Exception\SchemaViolationException;
11-
use SimpleSAML\XML\StringElementTrait;
11+
use SimpleSAML\XML\TypedTextContentTrait;
12+
use SimpleSAML\XMLSchema\Type\StringValue;
1213

1314
use function array_map;
1415
use function explode;
@@ -23,7 +24,10 @@
2324
*/
2425
abstract class AbstractComputedKeyOpenEnum extends AbstractWstElement
2526
{
26-
use StringElementTrait;
27+
use TypedTextContentTrait;
28+
29+
/** @var string */
30+
public const TEXTCONTENT_TYPE = StringValue::class;
2731

2832

2933
/**

src/XML/wst_200512/AbstractStatusCodeOpenEnum.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
use SimpleSAML\WSSecurity\Assert\Assert;
99
use SimpleSAML\XML\Exception\InvalidDOMElementException;
1010
use SimpleSAML\XML\Exception\SchemaViolationException;
11-
use SimpleSAML\XML\StringElementTrait;
11+
use SimpleSAML\XML\TypedTextContentTrait;
12+
use SimpleSAML\XMLSchema\Type\StringValue;
1213

1314
use function array_map;
1415
use function explode;
@@ -23,7 +24,10 @@
2324
*/
2425
abstract class AbstractStatusCodeOpenEnum extends AbstractWstElement
2526
{
26-
use StringElementTrait;
27+
use TypedTextContentTrait;
28+
29+
/** @var string */
30+
public const TEXTCONTENT_TYPE = StringValue::class;
2731

2832

2933
/**

src/XML/wst_200512/AuthenticationType.php

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

55
namespace SimpleSAML\WSSecurity\XML\wst_200512;
66

7-
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
8-
use SimpleSAML\XML\URIElementTrait;
9-
7+
use SimpleSAML\XML\SchemaValidatableElementInterface;
8+
use SimpleSAML\XML\SchemaValidatableElementTrait;
9+
use SimpleSAML\XML\TypedTextContentTrait;
10+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
1011
/**
1112
* A AuthenticationType element
1213
*
@@ -15,14 +16,9 @@
1516
final class AuthenticationType extends AbstractWstElement implements SchemaValidatableElementInterface
1617
{
1718
use SchemaValidatableElementTrait;
18-
use URIElementTrait;
19+
use TypedTextContentTrait;
1920

2021

21-
/**
22-
* @param string $content
23-
*/
24-
public function __construct(string $content)
25-
{
26-
$this->setContent($content);
27-
}
22+
/** @var string */
23+
public const TEXTCONTENT_TYPE = AnyURIValue::class;
2824
}

src/XML/wst_200512/CanonicalizationAlgorithm.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
namespace SimpleSAML\WSSecurity\XML\wst_200512;
66

7-
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
8-
use SimpleSAML\XML\URIElementTrait;
7+
use SimpleSAML\XML\SchemaValidatableElementInterface;
8+
use SimpleSAML\XML\SchemaValidatableElementTrait;
9+
use SimpleSAML\XML\TypedTextContentTrait;
10+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
911

1012
/**
1113
* A CanonicalizationAlgorithm element
@@ -15,14 +17,9 @@
1517
final class CanonicalizationAlgorithm extends AbstractWstElement implements SchemaValidatableElementInterface
1618
{
1719
use SchemaValidatableElementTrait;
18-
use URIElementTrait;
20+
use TypedTextContentTrait;
1921

2022

21-
/**
22-
* @param string $content
23-
*/
24-
public function __construct(string $content)
25-
{
26-
$this->setContent($content);
27-
}
23+
/** @var string */
24+
public const TEXTCONTENT_TYPE = AnyURIValue::class;
2825
}

0 commit comments

Comments
 (0)