diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php index be7d1be84cd3157c317dd01464e38c4bac4a277b..66953f9b9d2f2c82c46ce8e12e062c15cb4e498e 100644 --- a/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php +++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php @@ -64,19 +64,13 @@ class SimpleSAML_Metadata_MetaDataStorageHandler { ); } - $this->sources = array(); - - foreach($sourcesConfig as $elementConfig) { - if(!is_array($elementConfig)) { - throw new Exception( - 'Invalid configuration of the \'metadata.sources\' configuration option.' . - ' Every element in the array should be an associative array.' - ); - } - - $src = SimpleSAML_Metadata_MetaDataStorageSource::getSource($elementConfig); - $this->sources[] = $src; + try { + $this->sources = SimpleSAML_Metadata_MetaDataStorageSource::parseSources($sourcesConfig); + } catch (Exception $e) { + throw new Exception('Invalid configuration of the \'metadata.sources\'' . + ' configuration option: ' . $e->getMessage()); } + } diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageSource.php b/lib/SimpleSAML/Metadata/MetaDataStorageSource.php index 33f27e548a7692a7af02c1e34176a954bbe0ee85..42d6f1edf743aee4aa3542a138c81d7e3e7a2fd2 100644 --- a/lib/SimpleSAML/Metadata/MetaDataStorageSource.php +++ b/lib/SimpleSAML/Metadata/MetaDataStorageSource.php @@ -15,6 +15,33 @@ abstract class SimpleSAML_Metadata_MetaDataStorageSource { + /** + * Parse array with metadata sources. + * + * This function accepts an array with metadata sources, and returns an array with + * each metadata source as an object. + * + * @param array $sourcesConfig Array with metadata source configuration. + * @return array Parsed metadata configuration. + */ + public static function parseSources($sourcesConfig) { + assert('is_array($sourcesConfig)'); + + $sources = array(); + + foreach ($sourcesConfig as $sourceConfig) { + if (!is_array($sourceConfig)) { + throw new Exception('Found an element in metadata source' . + ' configuration which wasn\'t an array.'); + } + + $sources[] = self::getSource($sourceConfig); + } + + return $sources; + } + + /** * This function creates a metadata source based on the given configuration. * The type of source is based on the 'type' parameter in the configuration.