Skip to content
Snippets Groups Projects
Commit 2ab14178 authored by Olav Morken's avatar Olav Morken
Browse files

SimpleSAML_Utilities: Add getDefaultEndpoint-function.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1944 44740490-163a-0410-bde0-09ae8108e29a
parent 45b0af55
No related branches found
No related tags found
No related merge requests found
......@@ -2113,6 +2113,57 @@ class SimpleSAML_Utilities {
self::$logMask = $lastMask[1];
}
/**
* Find the default endpoint in an endpoint array.
*
* @param array $endpoints Array with endpoints.
* @param array $bindings Array with acceptable bindings. Can be NULL if any binding is allowed.
* @return array|NULL The default endpoint, or NULL if no acceptable endpoints are used.
*/
public static function getDefaultEndpoint(array $endpoints, array $bindings = NULL) {
$firstNotFalse = NULL;
$firstAllowed = NULL;
/* Look through the endpoint list for acceptable endpoints. */
foreach ($endpoints as $i => $ep) {
if ($bindings !== NULL && !in_array($ep['Binding'], $ep, TRUE)) {
/* Unsupported binding. Skip it. */
continue;
}
if (array_key_exists('isDefault', $ep)) {
if ($ep['isDefault'] === TRUE) {
/* This is the first endpoitn with isDefault set to TRUE. */
return $ep;
}
/* isDefault is set to FALSE, but the endpoint is still useable as a last resort. */
if ($firstAllowed === NULL) {
/* This is the first endpoint that we can use. */
$firstAllowed = $ep;
}
} else {
if ($firstNotFalse === NULL) {
/* This is the first endpoint without isDefault set. */
$firstNotFalse = $ep;
}
}
}
if ($firstNotFalse !== NULL) {
/* We have an endpoint without isDefault set to FALSE. */
return $firstNotFalse;
}
/*
* $firstAllowed either contains the first endpoint we can use, or it
* contains NULL if we cannot use any of the endpoints. Either way we
* return the value of it.
*/
return $firstAllowed;
}
}
?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment