SimpleSAML_Metadata_SAMLParser::parseDescriptorsFile PHP Method

parseDescriptorsFile() public static method

This function parses a file where the root node is either an EntityDescriptor element or an EntitiesDescriptor element. In both cases it will return an associative array of SAMLParser instances. If the file contains a single EntityDescriptorElement, then the array will contain a single SAMLParser instance.
public static parseDescriptorsFile ( string $file ) : SimpleSAML_Metadata_SAMLParser[]
$file string The path to the file which contains the EntityDescriptor or EntitiesDescriptor element.
return SimpleSAML_Metadata_SAMLParser[] An array of SAMLParser instances.
    public static function parseDescriptorsFile($file)
    {
        if ($file === null) {
            throw new Exception('Cannot open file NULL. File name not specified.');
        }
        $data = \SimpleSAML\Utils\HTTP::fetch($file);
        try {
            $doc = \SAML2\DOMDocumentFactory::fromString($data);
        } catch (\Exception $e) {
            throw new Exception('Failed to read XML from file: ' . $file);
        }
        if ($doc->documentElement === null) {
            throw new Exception('Opened file is not an XML document: ' . $file);
        }
        return self::parseDescriptorsElement($doc->documentElement);
    }

Usage Example

Example #1
0
 /**
  * This function processes a SAML metadata file.
  *
  * @param $src  Filename of the metadata file.
  */
 public function loadSource($source)
 {
     $entities = array();
     try {
         $entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsFile($source['src']);
     } catch (Exception $e) {
         SimpleSAML_Logger::warning('metarefresh: Failed to retrieve metadata. ' . $e->getMessage());
     }
     foreach ($entities as $entity) {
         if (array_key_exists('validateFingerprint', $source) && $source['validateFingerprint'] !== NULL) {
             if (!$entity->validateFingerprint($source['validateFingerprint'])) {
                 SimpleSAML_Logger::info('Skipping "' . $entity->getEntityId() . '" - could not verify signature.' . "\n");
                 continue;
             }
         }
         $template = NULL;
         if (array_key_exists('template', $source)) {
             $template = $source['template'];
         }
         $this->addMetadata($source['src'], $entity->getMetadata1xSP(), 'shib13-sp-remote', $template);
         $this->addMetadata($source['src'], $entity->getMetadata1xIdP(), 'shib13-idp-remote', $template);
         $this->addMetadata($source['src'], $entity->getMetadata20SP(), 'saml20-sp-remote', $template);
         $this->addMetadata($source['src'], $entity->getMetadata20IdP(), 'saml20-idp-remote', $template);
         $attributeAuthorities = $entity->getAttributeAuthorities();
         if (!empty($attributeAuthorities)) {
             $this->addMetadata($source['src'], $attributeAuthorities[0], 'attributeauthority-remote', $template);
         }
     }
 }
All Usage Examples Of SimpleSAML_Metadata_SAMLParser::parseDescriptorsFile