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

---
 lib/SimpleSAML/Utilities.php | 24 +++---------------------
 lib/SimpleSAML/Utils/XML.php | 31 +++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index b46c2903e..6e1266f0f 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -1226,28 +1226,10 @@ class SimpleSAML_Utilities {
 
 
 	/**
-	 * Format an XML string.
-	 *
-	 * This function formats an XML string using the formatDOMElement function.
-	 *
-	 * @param string $xml  XML string which should be formatted.
-	 * @param string $indentBase  Optional indentation which should be applied to all
-	 *                            the output. Optional, defaults to ''.
-	 * @return string  Formatted string.
+	 * @deprecated This function will be removed in SSP 2.0. Please use SimpleSAML\Utils\XML::formatXMLString() instead.
 	 */
 	public static function formatXMLString($xml, $indentBase = '') {
-		assert('is_string($xml)');
-		assert('is_string($indentBase)');
-
-		$doc = new DOMDocument();
-		if (!$doc->loadXML($xml)) {
-			throw new Exception('Error parsing XML string.');
-		}
-
-		$root = $doc->firstChild;
-		SimpleSAML\Utils\XML::formatDOMElement($root);
-
-		return $doc->saveXML($root);
+		return SimpleSAML\Utils\XML::formatXMLString($xml, $indentBase);
 	}
 
 	/**
@@ -1715,7 +1697,7 @@ class SimpleSAML_Utilities {
 			assert(FALSE);
 		}
 
-		$str = self::formatXMLString($message);
+		$str = SimpleSAML\Utils\XML::formatXMLString($message);
 		foreach (explode("\n", $str) as $line) {
 			SimpleSAML_Logger::debug($line);
 		}
diff --git a/lib/SimpleSAML/Utils/XML.php b/lib/SimpleSAML/Utils/XML.php
index faec37b5d..1aee76386 100644
--- a/lib/SimpleSAML/Utils/XML.php
+++ b/lib/SimpleSAML/Utils/XML.php
@@ -93,4 +93,35 @@ class XML
         // add indentation before closing tag
         $root->appendChild(new DOMText("\n".$indentBase));
     }
+
+    /**
+     * Format an XML string.
+     *
+     * This function formats an XML string using the formatDOMElement() function.
+     *
+     * @param string $xml An XML string which should be formatted.
+     * @param string $indentBase Optional indentation which should be applied to all the output. Optional, defaults
+     * to ''.
+     *
+     * @return string The formatted string.
+     *
+     * @throws SimpleSAML_Error_Exception If the input does not parse correctly as an XML string.
+     *
+     * @author Olav Morken, UNINETT AS <olav.morken@uninett.no>
+     */
+    public static function formatXMLString($xml, $indentBase = '')
+    {
+        assert('is_string($xml)');
+        assert('is_string($indentBase)');
+
+        $doc = new DOMDocument();
+        if (!$doc->loadXML($xml)) {
+            throw new SimpleSAML_Error_Exception('Error parsing XML string.');
+        }
+
+        $root = $doc->firstChild;
+        self::formatDOMElement($root, $indentBase);
+
+        return $doc->saveXML($root);
+    }
 }
-- 
GitLab