PHP Class SimpleSAML\Utils\XML

Show file Open project: simplesamlphp/simplesamlphp Class Usage Examples

Public Methods

Method Description
checkSAMLMessage ( string $message, string $type ) This function performs some sanity checks on XML documents, and optionally validates them against their schema if the 'validatexml' debugging option is enabled. A warning will be printed to the log if validation fails.
debugSAMLMessage ( string | DOMElement $message, string $type ) Helper function to log SAML messages that we send or receive.
formatDOMElement ( DOMElement $root, string $indentBase = '' ) Format a DOM element.
formatXMLString ( string $xml, string $indentBase = '' ) : string Format an XML string.
getDOMChildren ( DOMElement $element, string $localName, string $namespaceURI ) : array This function finds direct descendants of a DOM element with the specified localName and namespace. They are returned in an array.
getDOMText ( DOMElement $element ) : string This function extracts the text from DOMElements which should contain only text content.
isDOMElementOfType ( DOMNode $element, string $name, string $nsURI ) : boolean This function checks if the DOMElement has the correct localName and namespaceURI.
isValid ( string | DOMDocument $xml, string $schema ) : boolean | string This function attempts to validate an XML string against the specified schema. It will parse the string into a DOM document and validate this document against the schema.

Method Details

checkSAMLMessage() public static method

This function performs some sanity checks on XML documents, and optionally validates them against their schema if the 'validatexml' debugging option is enabled. A warning will be printed to the log if validation fails.
Author: Olav Morken, UNINETT AS ([email protected])
Author: Jaime Perez, UNINETT AS ([email protected])
public static checkSAMLMessage ( string $message, string $type )
$message string The SAML document we want to check.
$type string The type of document. Can be one of: - 'saml20' - 'saml11' - 'saml-meta'

debugSAMLMessage() public static method

Helper function to log SAML messages that we send or receive.
Author: Olav Morken, UNINETT AS ([email protected])
public static debugSAMLMessage ( string | DOMElement $message, string $type )
$message string | DOMElement The message, as an string containing the XML or an XML element.
$type string Whether this message is sent or received, encrypted or decrypted. The following values are supported: - 'in': for messages received. - 'out': for outgoing messages. - 'decrypt': for decrypted messages. - 'encrypt': for encrypted messages.

formatDOMElement() public static method

This function takes in a DOM element, and inserts whitespace to make it more readable. Note that whitespace added previously will be removed.
Author: Olav Morken, UNINETT AS ([email protected])
public static formatDOMElement ( DOMElement $root, string $indentBase = '' )
$root DOMElement The root element which should be formatted.
$indentBase string The indentation this element should be assumed to have. Defaults to an empty string.

formatXMLString() public static method

This function formats an XML string using the formatDOMElement() function.
Author: Olav Morken, UNINETT AS ([email protected])
public static formatXMLString ( string $xml, string $indentBase = '' ) : string
$xml string An XML string which should be formatted.
$indentBase string Optional indentation which should be applied to all the output. Optional, defaults to ''.
return string The formatted string.

getDOMChildren() public static method

This function accepts the same shortcuts for namespaces as the isDOMElementOfType function.
public static getDOMChildren ( DOMElement $element, string $localName, string $namespaceURI ) : array
$element DOMElement The element we should look in.
$localName string The name the element should have.
$namespaceURI string 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.

getDOMText() public static method

This function extracts the text from DOMElements which should contain only text content.
Author: Olav Morken, UNINETT AS ([email protected])
public static getDOMText ( DOMElement $element ) : string
$element DOMElement The element we should extract text from.
return string The text content of the element.

isDOMElementOfType() public static method

We also define the following shortcuts for namespaces: - '@ds': 'http://www.w3.org/2000/09/xmldsig#' - '@md': 'urn:oasis:names:tc:SAML:2.0:metadata' - '@saml1': 'urn:oasis:names:tc:SAML:1.0:assertion' - '@saml1md': 'urn:oasis:names:tc:SAML:profiles:v1metadata' - '@saml1p': 'urn:oasis:names:tc:SAML:1.0:protocol' - '@saml2': 'urn:oasis:names:tc:SAML:2.0:assertion' - '@saml2p': 'urn:oasis:names:tc:SAML:2.0:protocol'
Author: Andreas Solberg, UNINETT AS ([email protected])
Author: Olav Morken, UNINETT AS ([email protected])
public static isDOMElementOfType ( DOMNode $element, string $name, string $nsURI ) : boolean
$element DOMNode The element we should check.
$name string The local name the element should have.
$nsURI string The namespaceURI the element should have.
return boolean True if both namespace and local name matches, false otherwise.

isValid() public static method

Note that this function returns values that are evaluated as a logical true, both when validation works and when it doesn't. Please use strict comparisons to check the values returned.
Author: Olav Morken, UNINETT AS ([email protected])
public static isValid ( string | DOMDocument $xml, string $schema ) : boolean | string
$xml string | DOMDocument The XML string or document which should be validated.
$schema string The filename of the schema that should be used to validate the document.
return boolean | string Returns a string with errors found if validation fails. True if validation passes ok.