From a1d85164a7cd08098509a19cb0f4661715fc6a0f Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Thu, 3 Sep 2009 10:37:06 +0000 Subject: [PATCH] SimpleSAML_Auth_Source: Add getSourcesOfType(). git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1739 44740490-163a-0410-bde0-09ae8108e29a --- lib/SimpleSAML/Auth/Source.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/SimpleSAML/Auth/Source.php b/lib/SimpleSAML/Auth/Source.php index 413f68560..267c48df3 100644 --- a/lib/SimpleSAML/Auth/Source.php +++ b/lib/SimpleSAML/Auth/Source.php @@ -38,6 +38,39 @@ abstract class SimpleSAML_Auth_Source { } + /** + * Get sources of a specific type. + * + * @param string $type The type of the authentication source. + * @return array Array of SimpleSAML_Auth_Source objects of the specified type. + */ + public static function getSourcesOfType($type) { + assert('is_string($type)'); + + $config = SimpleSAML_Configuration::getConfig('authsources.php'); + + $ret = array(); + + $sources = $config->getOptions(); + foreach ($sources as $id) { + $source = $config->getArray($id); + + if (!array_key_exists(0, $source) || !is_string($source[0])) { + throw new Exception('Invalid authentication source \'' . $authId . + '\': First element must be a string which identifies the authentication source.'); + } + + if ($source[0] !== $type) { + continue; + } + + $ret[] = self::parseAuthSource($id, $source); + } + + return $ret; + } + + /** * Process a request. * -- GitLab