From 5cc426470ab98c68a6bb561a2f00e91aebe8a1fc Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Mon, 15 Sep 2008 13:52:49 +0000 Subject: [PATCH] Metadata sources - move parsing of sources-list to MetaDataStorageSource. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@872 44740490-163a-0410-bde0-09ae8108e29a --- .../Metadata/MetaDataStorageHandler.php | 18 +++++-------- .../Metadata/MetaDataStorageSource.php | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php index be7d1be84..66953f9b9 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 33f27e548..42d6f1edf 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. -- GitLab