diff --git a/lib/SimpleSAML/Metadata/SAMLParser.php b/lib/SimpleSAML/Metadata/SAMLParser.php index cc5b84eef430243e2cb305f306480bacfb39faef..c22e0c57012b6798e4683fba5c45d1fe2d11bd80 100644 --- a/lib/SimpleSAML/Metadata/SAMLParser.php +++ b/lib/SimpleSAML/Metadata/SAMLParser.php @@ -1016,7 +1016,7 @@ class SimpleSAML_Metadata_SAMLParser { $name = $attribute->getAttribute('Name'); $values = array_map( - array('SimpleSAML_Utilities', 'getDOMText'), + array('SimpleSAML\Utils\XML', 'getDOMText'), SimpleSAML_Utilities::getDOMChildren($attribute, 'AttributeValue', '@saml2') ); diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index 6e1266f0f2a2a68f40f391c133f8a7ee64284a36..ed7507b74f37aa1937734edee815aef99aa75728 100644 --- a/lib/SimpleSAML/Utilities.php +++ b/lib/SimpleSAML/Utilities.php @@ -752,28 +752,10 @@ class SimpleSAML_Utilities { /** - * This function extracts the text from DOMElements which should contain - * only text content. - * - * @param $element The element we should extract text from. - * @return The text content of the element. + * @deprecated This function will be removed in SSP 2.0. Please use SimpleSAML\Utils\XML::getDOMText() instead. */ public static function getDOMText($element) { - assert('$element instanceof DOMElement'); - - $txt = ''; - - for($i = 0; $i < $element->childNodes->length; $i++) { - $child = $element->childNodes->item($i); - if(!($child instanceof DOMText)) { - throw new Exception($element->localName . ' contained a non-text child node.'); - } - - $txt .= $child->wholeText; - } - - $txt = trim($txt); - return $txt; + return SimpleSAML\Utils\XML::getDOMText($element); } diff --git a/lib/SimpleSAML/Utils/XML.php b/lib/SimpleSAML/Utils/XML.php index d7d488ef1f18b016ee5e05ba2922f15e633d3587..0b47ec969d0f02b85bce28166bbf526bdd1655b2 100644 --- a/lib/SimpleSAML/Utils/XML.php +++ b/lib/SimpleSAML/Utils/XML.php @@ -127,4 +127,35 @@ class XML return $doc->saveXML($root); } + + + /** + * This function extracts the text from DOMElements which should contain only text content. + * + * @param \DOMElement $element The element we should extract text from. + * + * @return string The text content of the element. + * @throws \SimpleSAML_Error_Exception If the element contains a non-text child node. + * @author Olav Morken, UNINETT AS <olav.morken@uninett.no> + */ + public static function getDOMText(\DOMElement $element) + { + if (!($element instanceof \DOMElement)) { + throw new \SimpleSAML_Error_Exception('Invalid input parameters'); + } + + $txt = ''; + + for ($i = 0; $i < $element->childNodes->length; $i++) { + $child = $element->childNodes->item($i); + if (!($child instanceof \DOMText)) { + throw new \SimpleSAML_Error_Exception($element->localName.' contained a non-text child node.'); + } + + $txt .= $child->wholeText; + } + + $txt = trim($txt); + return $txt; + } }