Skip to content

Commit a5c7c1d

Browse files
authored
Feature/xpath util (#73)
* Add option-flag to XPath utility * Pass option on to parent * Bump xml-common
1 parent 9d04951 commit a5c7c1d

File tree

2 files changed

+6
-29
lines changed

2 files changed

+6
-29
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"ext-spl": "*",
4545

4646
"simplesamlphp/assert": "~1.9",
47-
"simplesamlphp/xml-common": "~2.3"
47+
"simplesamlphp/xml-common": "~2.4"
4848
},
4949
"require-dev": {
5050
"simplesamlphp/simplesamlphp-test-framework": "~1.10"

src/Utils/XPath.php

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

55
namespace SimpleSAML\XMLSecurity\Utils;
66

7-
use DOMDocument;
8-
use DOMElement;
97
use DOMNode;
108
use DOMXPath;
119
use SimpleSAML\XMLSecurity\Constants as C;
12-
use SimpleSAML\XMLSecurity\Exception\RuntimeException;
1310
use SimpleSAML\XPath\XPath as XPathUtils;
1411

1512
/**
@@ -23,38 +20,18 @@ class XPath extends XPathUtils
2320
* Get a DOMXPath object that can be used to search for XMLDSIG elements.
2421
*
2522
* @param \DOMNode $node The document to associate to the DOMXPath object.
23+
* @param bool $autoregister Whether to auto-register all namespaces used in the document
2624
*
2725
* @return \DOMXPath A DOMXPath object ready to use in the given document, with the XMLDSIG namespace already
2826
* registered.
2927
*/
30-
public static function getXPath(DOMNode $node): DOMXPath
28+
public static function getXPath(DOMNode $node, bool $autoregister = false): DOMXPath
3129
{
32-
$xp = parent::getXPath($node);
30+
$xp = parent::getXPath($node, $autoregister);
31+
3332
$xp->registerNamespace('ds', C::NS_XDSIG);
3433
$xp->registerNamespace('xenc', C::NS_XENC);
35-
return $xp;
36-
}
37-
3834

39-
/**
40-
* Search for an element with a certain name among the children of a reference element.
41-
*
42-
* @param \DOMNode $ref The DOMDocument or DOMElement where encrypted data is expected to be found as a child.
43-
* @param string $name The name (possibly prefixed) of the element we are looking for.
44-
*
45-
* @return \DOMElement|false The element we are looking for, or false when not found.
46-
*
47-
* @throws \SimpleSAML\XMLSecurity\Exception\RuntimeException If no DOM document is available.
48-
*/
49-
public static function findElement(DOMNode $ref, string $name): DOMElement|false
50-
{
51-
$doc = $ref instanceof DOMDocument ? $ref : $ref->ownerDocument;
52-
if ($doc === null) {
53-
throw new RuntimeException('Cannot search, no DOMDocument available');
54-
}
55-
56-
$nodeset = self::getXPath($doc)->query('./' . $name, $ref);
57-
58-
return $nodeset->item(0) ?? false;
35+
return $xp;
5936
}
6037
}

0 commit comments

Comments
 (0)