SimpleSAML_Metadata_SAMLParser::parseDescriptorsString PHP Method

parseDescriptorsString() public static method

This function parses a string with XML data. The root node of the XML data is expected to be either an EntityDescriptor element or an EntitiesDescriptor element. It will return an associative array of SAMLParser instances.
public static parseDescriptorsString ( string $string ) : SimpleSAML_Metadata_SAMLParser[]
$string string The string with XML data.
return SimpleSAML_Metadata_SAMLParser[] An associative array of SAMLParser instances. The key of the array will be the entity id.
    public static function parseDescriptorsString($string)
    {
        try {
            $doc = \SAML2\DOMDocumentFactory::fromString($string);
        } catch (\Exception $e) {
            throw new Exception('Failed to parse XML string.');
        }
        return self::parseDescriptorsElement($doc->documentElement);
    }

Usage Example

Example #1
0
function convert_metadata($xmldata)
{
    $config = SimpleSAML_Configuration::getInstance();
    if ($xmldata) {
        $xmldata = htmlspecialchars_decode($xmldata);
        SimpleSAML_Utilities::validateXMLDocument($xmldata, 'saml-meta');
        $entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsString($xmldata);
        foreach ($entities as &$entity) {
            $entity = array('shib13-sp-remote' => $entity->getMetadata1xSP(), 'shib13-idp-remote' => $entity->getMetadata1xIdP(), 'saml20-sp-remote' => $entity->getMetadata20SP(), 'saml20-idp-remote' => $entity->getMetadata20IdP());
        }
        $output = array($entity['saml20-sp-remote']['entityid'] => $entity['saml20-sp-remote']);
    } else {
        $xmldata = '';
        $output = array();
    }
    return $output;
}
All Usage Examples Of SimpleSAML_Metadata_SAMLParser::parseDescriptorsString