diff options
author | Jaime Perez Crespo <jaime.perez@uninett.no> | 2015-08-04 17:42:32 +0200 |
---|---|---|
committer | Jaime Perez Crespo <jaime.perez@uninett.no> | 2015-08-04 17:42:32 +0200 |
commit | c6698baddd397e7642741d5bc204457a7eea570c (patch) | |
tree | 9ed90a6b2b36953ed1245fffc193fda520cd9d0a /lib/SimpleSAML/Auth/Source.php | |
parent | fe685373e8301a07b66e4923fb441955c03afea8 (diff) | |
download | simplesamlphp-c6698baddd397e7642741d5bc204457a7eea570c.zip simplesamlphp-c6698baddd397e7642741d5bc204457a7eea570c.tar.gz simplesamlphp-c6698baddd397e7642741d5bc204457a7eea570c.tar.bz2 |
Resolve duplication of code.
Diffstat (limited to 'lib/SimpleSAML/Auth/Source.php')
-rw-r--r-- | lib/SimpleSAML/Auth/Source.php | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/lib/SimpleSAML/Auth/Source.php b/lib/SimpleSAML/Auth/Source.php index fef90b5..4f071fa 100644 --- a/lib/SimpleSAML/Auth/Source.php +++ b/lib/SimpleSAML/Auth/Source.php @@ -61,12 +61,7 @@ abstract class SimpleSAML_Auth_Source foreach ($sources as $id) { $source = $config->getArray($id); - if (!array_key_exists(0, $source) || !is_string($source[0])) { - throw new Exception( - 'Invalid authentication source \''.$id. - '\': First element must be a string which identifies the authentication source.' - ); - } + self::validateSource($source, $id); if ($source[0] !== $type) { continue; @@ -213,12 +208,7 @@ abstract class SimpleSAML_Auth_Source assert('is_string($authId)'); assert('is_array($config)'); - if (!array_key_exists(0, $config) || !is_string($config[0])) { - throw new Exception( - 'Invalid authentication source \''.$authId. - '\': First element must be a string which identifies the authentication source.' - ); - } + self::validateSource($config, $authId); $className = SimpleSAML_Module::resolveClass($config[0], 'Auth_Source', 'SimpleSAML_Auth_Source'); @@ -375,4 +365,23 @@ abstract class SimpleSAML_Auth_Source return $config->getOptions(); } + + + /** + * Make sure that the first element of an auth source is its identifier. + * + * @param array $source An array with the auth source configuration. + * @param string $id The auth source identifier. + * + * @throws Exception If the first element of $source is not an identifier for the auth source. + */ + protected static function validateSource($source, $id) + { + if (!array_key_exists(0, $source) || !is_string($source[0])) { + throw new Exception( + 'Invalid authentication source \''.$id. + '\': First element must be a string which identifies the authentication source.' + ); + } + } } |