Skip to content
Snippets Groups Projects
Commit 44818e22 authored by Jaime Perez Crespo's avatar Jaime Perez Crespo
Browse files

Move SimpleSAML_Utilities::formatXMLString() to...

Move SimpleSAML_Utilities::formatXMLString() to SimpleSAML\Utils\XML::formatXMLString(). Deprecate the former.
parent 7827bfc5
No related branches found
No related tags found
No related merge requests found
...@@ -1226,28 +1226,10 @@ class SimpleSAML_Utilities { ...@@ -1226,28 +1226,10 @@ class SimpleSAML_Utilities {
/** /**
* Format an XML string. * @deprecated This function will be removed in SSP 2.0. Please use SimpleSAML\Utils\XML::formatXMLString() instead.
*
* 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.
*/ */
public static function formatXMLString($xml, $indentBase = '') { public static function formatXMLString($xml, $indentBase = '') {
assert('is_string($xml)'); return SimpleSAML\Utils\XML::formatXMLString($xml, $indentBase);
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);
} }
/** /**
...@@ -1715,7 +1697,7 @@ class SimpleSAML_Utilities { ...@@ -1715,7 +1697,7 @@ class SimpleSAML_Utilities {
assert(FALSE); assert(FALSE);
} }
$str = self::formatXMLString($message); $str = SimpleSAML\Utils\XML::formatXMLString($message);
foreach (explode("\n", $str) as $line) { foreach (explode("\n", $str) as $line) {
SimpleSAML_Logger::debug($line); SimpleSAML_Logger::debug($line);
} }
......
...@@ -93,4 +93,35 @@ class XML ...@@ -93,4 +93,35 @@ class XML
// add indentation before closing tag // add indentation before closing tag
$root->appendChild(new DOMText("\n".$indentBase)); $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);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment