From 3cc3abdb78630899f80606675580af0c30ffedb9 Mon Sep 17 00:00:00 2001
From: Jaime Perez Crespo <jaime.perez@uninett.no>
Date: Mon, 20 Apr 2015 14:48:22 +0200
Subject: [PATCH] Move SimpleSAML_Utilities::getDOMChildren() to
 SimpleSAML\Utils\XML::getDOMChildren(). Deprecate the former.

---
 lib/SimpleSAML/Bindings/Shib13/Artifact.php |  4 +--
 lib/SimpleSAML/Bindings/Shib13/HTTPPost.php |  2 +-
 lib/SimpleSAML/Metadata/SAMLParser.php      |  2 +-
 lib/SimpleSAML/Utilities.php                | 31 ++---------------
 lib/SimpleSAML/Utils/XML.php                | 37 +++++++++++++++++++++
 5 files changed, 43 insertions(+), 33 deletions(-)

diff --git a/lib/SimpleSAML/Bindings/Shib13/Artifact.php b/lib/SimpleSAML/Bindings/Shib13/Artifact.php
index 23f43524b..0623bd175 100644
--- a/lib/SimpleSAML/Bindings/Shib13/Artifact.php
+++ b/lib/SimpleSAML/Bindings/Shib13/Artifact.php
@@ -84,14 +84,14 @@ class SimpleSAML_Bindings_Shib13_Artifact {
 			throw new SimpleSAML_Error_Exception('Expected artifact response to contain a <soap:Envelope> element.');
 		}
 
-		$soapBody = SimpleSAML_Utilities::getDOMChildren($soapEnvelope, 'Body', 'http://schemas.xmlsoap.org/soap/envelope/');
+		$soapBody = SimpleSAML\Utils\XML::getDOMChildren($soapEnvelope, 'Body', 'http://schemas.xmlsoap.org/soap/envelope/');
 		if (count($soapBody) === 0) {
 			throw new SimpleSAML_Error_Exception('Couldn\'t find <soap:Body> in <soap:Envelope>.');
 		}
 		$soapBody = $soapBody[0];
 
 
-		$responseElement = SimpleSAML_Utilities::getDOMChildren($soapBody, 'Response', 'urn:oasis:names:tc:SAML:1.0:protocol');
+		$responseElement = SimpleSAML\Utils\XML::getDOMChildren($soapBody, 'Response', 'urn:oasis:names:tc:SAML:1.0:protocol');
 		if (count($responseElement) === 0) {
 			throw new SimpleSAML_Error_Exception('Couldn\'t find <saml1p:Response> in <soap:Body>.');
 		}
diff --git a/lib/SimpleSAML/Bindings/Shib13/HTTPPost.php b/lib/SimpleSAML/Bindings/Shib13/HTTPPost.php
index 7cb87a8f7..b10522560 100644
--- a/lib/SimpleSAML/Bindings/Shib13/HTTPPost.php
+++ b/lib/SimpleSAML/Bindings/Shib13/HTTPPost.php
@@ -67,7 +67,7 @@ class SimpleSAML_Bindings_Shib13_HTTPPost {
 		if ($signResponse) {
 			/* Sign the response - this must be done after encrypting the assertion. */
 			/* We insert the signature before the saml2p:Status element. */
-			$statusElements = SimpleSAML_Utilities::getDOMChildren($responseroot, 'Status', '@saml1p');
+			$statusElements = SimpleSAML\Utils\XML::getDOMChildren($responseroot, 'Status', '@saml1p');
 			assert('count($statusElements) === 1');
 			$signer->sign($responseroot, $responseroot, $statusElements[0]);
 
diff --git a/lib/SimpleSAML/Metadata/SAMLParser.php b/lib/SimpleSAML/Metadata/SAMLParser.php
index 34e962fe1..3b9be1191 100644
--- a/lib/SimpleSAML/Metadata/SAMLParser.php
+++ b/lib/SimpleSAML/Metadata/SAMLParser.php
@@ -1017,7 +1017,7 @@ class SimpleSAML_Metadata_SAMLParser {
 				$name = $attribute->getAttribute('Name');
 				$values = array_map(
 					array('SimpleSAML\Utils\XML', 'getDOMText'),
-					SimpleSAML_Utilities::getDOMChildren($attribute, 'AttributeValue', '@saml2')
+                    SimpleSAML\Utils\XML::getDOMChildren($attribute, 'AttributeValue', '@saml2')
 				);
 
 				if ($name === 'tags') {
diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index 10d3cec41..94c5fe56c 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -661,37 +661,10 @@ class SimpleSAML_Utilities {
 
 
 	/**
-	 * This function finds direct descendants of a DOM element with the specified
-	 * localName and namespace. They are returned in an array.
-	 *
-	 * This function accepts the same shortcuts for namespaces as the isDOMElementOfType function.
-	 *
-	 * @param DOMElement $element  The element we should look in.
-	 * @param string $localName  The name the element should have.
-	 * @param string $namespaceURI  The namespace the element should have.
-	 * @return array  Array with the matching elements in the order they are found. An empty array is
-	 *         returned if no elements match.
+	 * @deprecated This function will be removed in SSP 2.0. Please use SimpleSAML\Utils\XML::getDOMChildren() instead.
 	 */
 	public static function getDOMChildren(DOMElement $element, $localName, $namespaceURI) {
-		assert('is_string($localName)');
-		assert('is_string($namespaceURI)');
-
-		$ret = array();
-
-		for($i = 0; $i < $element->childNodes->length; $i++) {
-			$child = $element->childNodes->item($i);
-
-			/* Skip text nodes and comment elements. */
-			if($child instanceof DOMText || $child instanceof DOMComment) {
-				continue;
-			}
-
-			if(self::isDOMElementOfType($child, $localName, $namespaceURI) === TRUE) {
-				$ret[] = $child;
-			}
-		}
-
-		return $ret;
+		return SimpleSAML\Utils\XML::getDOMChildren($element, $localName, $namespaceURI);
 	}
 
 
diff --git a/lib/SimpleSAML/Utils/XML.php b/lib/SimpleSAML/Utils/XML.php
index 5a2b3da35..e18d7ff74 100644
--- a/lib/SimpleSAML/Utils/XML.php
+++ b/lib/SimpleSAML/Utils/XML.php
@@ -130,6 +130,43 @@ class XML
     }
 
 
+    /**
+     * This function finds direct descendants of a DOM element with the specified
+     * localName and namespace. They are returned in an array.
+     *
+     * This function accepts the same shortcuts for namespaces as the isDOMElementOfType function.
+     *
+     * @param \DOMElement $element The element we should look in.
+     * @param string      $localName The name the element should have.
+     * @param string      $namespaceURI The namespace the element should have.
+     *
+     * @return array  Array with the matching elements in the order they are found. An empty array is
+     *         returned if no elements match.
+     */
+    public static function getDOMChildren(\DOMElement $element, $localName, $namespaceURI)
+    {
+        assert('is_string($localName)');
+        assert('is_string($namespaceURI)');
+
+        $ret = array();
+
+        for ($i = 0; $i < $element->childNodes->length; $i++) {
+            $child = $element->childNodes->item($i);
+
+            // skip text nodes and comment elements
+            if ($child instanceof \DOMText || $child instanceof \DOMComment) {
+                continue;
+            }
+
+            if (self::isDOMElementOfType($child, $localName, $namespaceURI) === true) {
+                $ret[] = $child;
+            }
+        }
+
+        return $ret;
+    }
+
+
     /**
      * This function extracts the text from DOMElements which should contain only text content.
      *
-- 
GitLab