From 69fdcc7f8da9b83dd1fdd8773669922cb551901a Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Wed, 4 Nov 2009 13:51:53 +0000
Subject: [PATCH] SimpleSAML_Configuration: Add getDefaultEndpoint function.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1945 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Configuration.php | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/lib/SimpleSAML/Configuration.php b/lib/SimpleSAML/Configuration.php
index 3bca636a7..d46a1993a 100644
--- a/lib/SimpleSAML/Configuration.php
+++ b/lib/SimpleSAML/Configuration.php
@@ -944,6 +944,32 @@ class SimpleSAML_Configuration {
 		return $eps;
 	}
 
+
+	/**
+	 * Find the default endpoint of the given type.
+	 *
+	 * @param string $endpointType  The endpoint type.
+	 * @param array $bindings  Array with acceptable bindings. Can be NULL if any binding is allowed.
+	 * @param mixed $default  The default value to return if no matching endpoint is found. If no default is provided, an exception will be thrown.
+	 * @return  array|NULL  The default endpoint, or NULL if no acceptable endpoints are used.
+	 */
+	public function getDefaultEndpoint($endpointType, array $bindings = NULL, $default = self::REQUIRED_OPTION) {
+		assert('is_string($endpointType)');
+
+		$endpoints = $this->getEndpoints($endpointType);
+		$defaultEndpoint = SimpleSAML_Utilities::getDefaultEndpoint($endpoints, $bindings);
+		if ($defaultEndpoint !== NULL) {
+			return $defaultEndpoint;
+		}
+
+		if ($default === self::REQUIRED_OPTION) {
+			$loc = $this->location . '[' . var_export($endpointType, TRUE) . ']:';
+			throw new Exception($loc . 'Could not find a supported ' . $endpointType . ' endpoint.');
+		}
+
+		return $default;
+	}
+
 }
 
 ?>
\ No newline at end of file
-- 
GitLab