diff options
Diffstat (limited to 'lib/SimpleSAML')
-rw-r--r-- | lib/SimpleSAML/Configuration.php | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/lib/SimpleSAML/Configuration.php b/lib/SimpleSAML/Configuration.php index 4c0b878..2a52bf1 100644 --- a/lib/SimpleSAML/Configuration.php +++ b/lib/SimpleSAML/Configuration.php @@ -121,8 +121,10 @@ class SimpleSAML_Configuration // file does not exist, but is required throw new Exception('Missing configuration file: '.$filename); } else { - // file does not exist, but is optional - $config = array(); + // file does not exist, but is optional, so return an empty configuration object without saving it + $cfg = new SimpleSAML_Configuration(array(), $filename); + $cfg->filename = $filename; + return $cfg; } $cfg = new SimpleSAML_Configuration($config, $filename); @@ -212,15 +214,22 @@ class SimpleSAML_Configuration * * @param array $config The configuration array. * @param string $location The location which will be given when an error occurs. Optional. + * @param string|null $instance The name of this instance. If specified, the configuration will be loaded and an + * instance with that name will be kept for it to be retrieved later with getInstance($instance). If null, the + * configuration will not be kept for later use. Defaults to null. * * @return SimpleSAML_Configuration The configuration object. */ - public static function loadFromArray($config, $location = '[ARRAY]') + public static function loadFromArray($config, $location = '[ARRAY]', $instance = null) { assert('is_array($config)'); assert('is_string($location)'); - return new SimpleSAML_Configuration($config, $location); + $c = new SimpleSAML_Configuration($config, $location); + if ($instance !== null) { + self::$instance[$instance] = $c; + } + return $c; } @@ -243,14 +252,16 @@ class SimpleSAML_Configuration { assert('is_string($instancename)'); + // check if the instance exists already + if (array_key_exists($instancename, self::$instance)) { + return self::$instance[$instancename]; + } + if ($instancename === 'simplesaml') { return self::getConfig(); } - if (!array_key_exists($instancename, self::$instance)) { - throw new Exception('Configuration with name '.$instancename.' is not initialized.'); - } - return self::$instance[$instancename]; + throw new Exception('Configuration with name '.$instancename.' is not initialized.'); } |