SimpleSAML_Metadata_SAMLParser::parseString PHP Метод

parseString() публичный статический Метод

This function parses a string which contains XML encoded metadata.
public static parseString ( string $metadata ) : SimpleSAML_Metadata_SAMLParser
$metadata string A string which contains XML encoded metadata.
Результат SimpleSAML_Metadata_SAMLParser An instance of this class with the metadata loaded.
    public static function parseString($metadata)
    {
        try {
            $doc = \SAML2\DOMDocumentFactory::fromString($metadata);
        } catch (\Exception $e) {
            throw new Exception('Failed to parse XML string.');
        }
        return self::parseDocument($doc);
    }

Usage Example

 /**
  * Overriding this function from the superclass SimpleSAML_Metadata_MetaDataStorageSource.
  *
  * This function retrieves metadata for the given entity id in the given set of metadata.
  * It will return NULL if it is unable to locate the metadata.
  *
  * This class implements this function using the getMetadataSet-function. A subclass should
  * override this function if it doesn't implement the getMetadataSet function, or if the
  * implementation of getMetadataSet is slow.
  *
  * @param $index  The entityId or metaindex we are looking up.
  * @param $set  The set we are looking for metadata in.
  * @return An associative array with metadata for the given entity, or NULL if we are unable to
  *         locate the entity.
  */
 public function getMetaData($index, $set)
 {
     assert('is_string($index)');
     assert('is_string($set)');
     SimpleSAML_Logger::info('MetaData - Handler.MDX: Loading metadata entity [' . $index . '] from [' . $set . ']');
     /* Read from cache if possible. */
     $data = $this->getFromCache($set, $index);
     if ($data !== NULL && array_key_exists('expires', $data) && $data['expires'] < time()) {
         /* Metadata has expired. */
         $data = NULL;
     }
     if (isset($data)) {
         /* Metadata found in cache and not expired. */
         SimpleSAML_Logger::debug('MetaData - Handler.MDX: Using cached metadata for: ' . $index . '.');
         return $data;
     }
     /* Look at Metadata Query Protocol: https://github.com/iay/md-query/blob/master/draft-young-md-query.txt */
     $mdx_url = $this->server . '/entities/' . urlencode($index);
     SimpleSAML_Logger::debug('MetaData - Handler.MDX: Downloading metadata for "' . $index . '" from [' . $mdx_url . ']');
     try {
         $xmldata = \SimpleSAML\Utils\HTTP::fetch($mdx_url);
     } catch (Exception $e) {
         SimpleSAML_Logger::warning('Fetching metadata for ' . $index . ': ' . $e->getMessage());
     }
     if (empty($xmldata)) {
         $error = error_get_last();
         throw new Exception('Error downloading metadata for "' . $index . '" from "' . $mdx_url . '": ' . $error['message']);
     }
     $entity = SimpleSAML_Metadata_SAMLParser::parseString($xmldata);
     SimpleSAML_Logger::debug('MetaData - Handler.MDX: Completed parsing of [' . $mdx_url . ']');
     if ($this->validateFingerprint !== NULL) {
         if (!$entity->validateFingerprint($this->validateFingerprint)) {
             throw new Exception('Error, could not verify signature for entity: ' . $index . '".');
         }
     }
     $data = self::getParsedSet($entity, $set);
     if ($data === NULL) {
         throw new Exception('No metadata for set "' . $set . '" available from "' . $index . '".');
     }
     $this->writeToCache($set, $index, $data);
     return $data;
 }
All Usage Examples Of SimpleSAML_Metadata_SAMLParser::parseString