function writeMetadataFiles($outputDir)
{
while (strlen($outputDir) > 0 && $outputDir[strlen($outputDir) - 1] === '/') {
$outputDir = substr($outputDir, 0, strlen($outputDir) - 1);
}
if (!file_exists($outputDir)) {
SimpleSAML\Logger::info('Creating directory: ' . $outputDir . "\n");
$res = @mkdir($outputDir, 0777, TRUE);
if ($res === FALSE) {
throw new Exception('Error creating directory: ' . $outputDir);
}
}
foreach ($this->types as $type) {
$filename = $outputDir . '/' . $type . '.php';
if (array_key_exists($type, $this->metadata)) {
$elements = $this->metadata[$type];
SimpleSAML\Logger::debug('Writing: ' . $filename);
$content = '<?php' . "\n" . '/* This file was generated by the metarefresh module at ' . $this->getTime() . "\n";
$content .= ' Do not update it manually as it will get overwritten' . "\n" . '*/' . "\n";
foreach ($elements as $m) {
$entityID = $m['metadata']['entityid'];
$content .= "\n";
$content .= '$metadata[\'' . addslashes($entityID) . '\'] = ' . var_export($m['metadata'], TRUE) . ';' . "\n";
}
$content .= "\n" . '?>';
SimpleSAML\Utils\System::writeFile($filename, $content, 0644);
} elseif (is_file($filename)) {
if (unlink($filename)) {
SimpleSAML\Logger::debug('Deleting stale metadata file: ' . $filename);
} else {
SimpleSAML\Logger::warning('Could not delete stale metadata file: ' . $filename);
}
}
}
}