Skip to content
Snippets Groups Projects
Commit 3d03f6d7 authored by Dominic Benson's avatar Dominic Benson
Browse files

Allow a configuration to be pre-loaded as if from a file

With a dynamic configuration, it is not desirable to load from literal files
By storing a configuration object against a filepath, subsequent calls to
getConfig work transparently, bypassing the disk load step.
parent 93594a77
No related branches found
No related tags found
No related merge requests found
......@@ -194,6 +194,35 @@ class SimpleSAML_Configuration implements \SimpleSAML\Utils\ClearableState
self::$configDirs[$configSet] = $path;
}
/**
* Store a pre-initialized configuration.
*
* Allows consumers to create configuration objects without having them
* loaded from a file.
*
* @param SimpleSAML_Configuration $config The configuration object to store
* @param string $filename The name of the configuration file.
* @param string $configSet The configuration set. Optional, defaults to 'simplesaml'.
*/
public static function setPreLoadedConfig(SimpleSAML_Configuration $config, $filename = 'config.php', $configSet = 'simplesaml')
{
assert(is_string($filename));
assert(is_string($configSet));
if (!array_key_exists($configSet, self::$configDirs)) {
if ($configSet !== 'simplesaml') {
throw new Exception('Configuration set \'' . $configSet . '\' not initialized.');
} else {
self::$configDirs['simplesaml'] = dirname(dirname(dirname(__FILE__))) . '/config';
}
}
$dir = self::$configDirs[$configSet];
$filePath = $dir . '/' . $filename;
self::$loadedConfigs[$filePath] = $config;
}
/**
* Load a configuration file from a configuration set.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment