Revision: 1944
Author: olavmrk
Date: Wed Nov  4 05:51:43 2009
Log: SimpleSAML_Utilities: Add getDefaultEndpoint-function.
http://code.google.com/p/simplesamlphp/source/detail?r=1944

Modified:
  /trunk/lib/SimpleSAML/Utilities.php

=======================================
--- /trunk/lib/SimpleSAML/Utilities.php Tue Oct 20 02:14:30 2009
+++ /trunk/lib/SimpleSAML/Utilities.php Wed Nov  4 05:51:43 2009
@@ -2112,6 +2112,57 @@
                error_reporting($lastMask[0]);
                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;
+       }

  }


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"simpleSAMLphp commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/simplesamlphp-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to