SimpleSAML_Metadata_MetaDataStorageHandlerSerialize::getMetadataSets PHP Method

getMetadataSets() public method

Retrieve a list of all available metadata sets.
public getMetadataSets ( ) : array
return array An array with the available sets.
    public function getMetadataSets()
    {
        $ret = array();
        $dh = @opendir($this->directory);
        if ($dh === false) {
            SimpleSAML\Logger::warning('Serialize metadata handler: Unable to open directory: ' . var_export($this->directory, true));
            return $ret;
        }
        while (($entry = readdir($dh)) !== false) {
            if ($entry[0] === '.') {
                // skip '..', '.' and hidden files
                continue;
            }
            $path = $this->directory . '/' . $entry;
            if (!is_dir($path)) {
                SimpleSAML\Logger::warning('Serialize metadata handler: Metadata directory contained a file where only directories should ' . 'exist: ' . var_export($path, true));
                continue;
            }
            $ret[] = rawurldecode($entry);
        }
        closedir($dh);
        return $ret;
    }

Usage Example

Example #1
0
 /**
  * Save metadata for loading with the 'serialize' metadata loader.
  *
  * @param string $outputDir  The directory we should save the metadata to.
  */
 public function writeMetadataSerialize($outputDir)
 {
     assert('is_string($outputDir)');
     $metaHandler = new SimpleSAML_Metadata_MetaDataStorageHandlerSerialize(array('directory' => $outputDir));
     /* First we add all the metadata entries to the metadata handler. */
     foreach ($this->metadata as $set => $elements) {
         foreach ($elements as $m) {
             $entityId = $m['metadata']['entityid'];
             SimpleSAML_Logger::debug('metarefresh: Add metadata entry ' . var_export($entityId, TRUE) . ' in set ' . var_export($set, TRUE) . '.');
             $metaHandler->saveMetadata($entityId, $set, $m['metadata']);
         }
     }
     /* Then we delete old entries which should no longer exist. */
     $ct = time();
     foreach ($metaHandler->getMetadataSets() as $set) {
         foreach ($metaHandler->getMetadataSet($set) as $entityId => $metadata) {
             if (!array_key_exists('expire', $metadata)) {
                 SimpleSAML_Logger::warning('metarefresh: Metadata entry without expire timestamp: ' . var_export($entityId, TRUE) . ' in set ' . var_export($set, TRUE) . '.');
                 continue;
             }
             if ($metadata['expire'] > $ct) {
                 continue;
             }
             SimpleSAML_Logger::debug('metarefresh: ' . $entityId . ' expired ' . date('l jS \\of F Y h:i:s A', $metadata['expire']));
             SimpleSAML_Logger::debug('metarefresh: Delete expired metadata entry ' . var_export($entityId, TRUE) . ' in set ' . var_export($set, TRUE) . '. (' . ($ct - $metadata['expire']) . ' sec)');
             $metaHandler->deleteMetadata($entityId, $set);
         }
     }
 }