sspmod_metarefresh_MetaLoader::writeARPfile PHP Method

writeARPfile() public method

This function writes the metadata to an ARP file
public writeARPfile ( $config )
    function writeARPfile($config)
    {
        assert('is_a($config, \'SimpleSAML_Configuration\')');
        $arpfile = $config->getValue('arpfile');
        $types = array('saml20-sp-remote');
        $md = array();
        foreach ($this->metadata as $category => $elements) {
            if (!in_array($category, $types)) {
                continue;
            }
            $md = array_merge($md, $elements);
        }
        // $metadata, $attributemap, $prefix, $suffix
        $arp = new sspmod_metarefresh_ARP($md, $config->getValue('attributemap', ''), $config->getValue('prefix', ''), $config->getValue('suffix', ''));
        $arpxml = $arp->getXML();
        SimpleSAML\Logger::info('Writing ARP file: ' . $arpfile . "\n");
        file_put_contents($arpfile, $arpxml);
    }

Usage Example

Example #1
0
/**
 * Hook to run a cron job.
 *
 * @param array &$croninfo  Output
 */
function metarefresh_hook_cron(&$croninfo)
{
    assert('is_array($croninfo)');
    assert('array_key_exists("summary", $croninfo)');
    assert('array_key_exists("tag", $croninfo)');
    SimpleSAML_Logger::info('cron [metarefresh]: Running cron in cron tag [' . $croninfo['tag'] . '] ');
    try {
        $config = SimpleSAML_Configuration::getInstance();
        $mconfig = SimpleSAML_Configuration::getConfig('config-metarefresh.php');
        $sets = $mconfig->getConfigList('sets');
        foreach ($sets as $setkey => $set) {
            // Only process sets where cron matches the current cron tag.
            $cronTags = $set->getArray('cron');
            if (!in_array($croninfo['tag'], $cronTags)) {
                continue;
            }
            SimpleSAML_Logger::info('cron [metarefresh]: Executing set [' . $setkey . ']');
            $expireAfter = $set->getInteger('expireAfter', NULL);
            if ($expireAfter !== NULL) {
                $expire = time() + $expireAfter;
            } else {
                $expire = NULL;
            }
            $metaloader = new sspmod_metarefresh_MetaLoader($expire);
            foreach ($set->getArray('sources') as $source) {
                SimpleSAML_Logger::debug('cron [metarefresh]: In set [' . $setkey . '] loading source [' . $source['src'] . ']');
                $metaloader->loadSource($source);
            }
            $outputDir = $set->getString('outputDir');
            $outputDir = $config->resolvePath($outputDir);
            $outputFormat = $set->getValueValidate('outputFormat', array('flatfile', 'serialize'), 'flatfile');
            switch ($outputFormat) {
                case 'flatfile':
                    $metaloader->writeMetadataFiles($outputDir);
                    break;
                case 'serialize':
                    $metaloader->writeMetadataSerialize($outputDir);
                    break;
            }
            if ($set->hasValue('arp')) {
                $arpconfig = SimpleSAML_Configuration::loadFromArray($set->getValue('arp'));
                $metaloader->writeARPfile($arpconfig);
            }
        }
    } catch (Exception $e) {
        $croninfo['summary'][] = 'Error during metarefresh: ' . $e->getMessage();
    }
}
All Usage Examples Of sspmod_metarefresh_MetaLoader::writeARPfile