Skip to content

Commit a9acec7

Browse files
committed
Add option-flag to XPath utility
1 parent a4fd1b5 commit a9acec7

File tree

1 file changed

+2
-27
lines changed

1 file changed

+2
-27
lines changed

src/Utils/XPath.php

Lines changed: 2 additions & 27 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,16 @@ 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
{
3230
$xp = parent::getXPath($node);
3331
$xp->registerNamespace('ds', C::NS_XDSIG);
3432
$xp->registerNamespace('xenc', C::NS_XENC);
3533
return $xp;
3634
}
37-
38-
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 DOM document available');
54-
}
55-
56-
$nodeset = self::getXPath($doc)->query('./' . $name, $ref);
57-
58-
return $nodeset->item(0) ?? false;
59-
}
6035
}

0 commit comments

Comments
 (0)