From e911e26723298e2ebd3c85e73da2164669e8cb79 Mon Sep 17 00:00:00 2001
From: Jaime Perez Crespo <jaime.perez@uninett.no>
Date: Tue, 21 Apr 2015 13:03:16 +0200
Subject: [PATCH] Move SimpleSAML_Utilities::getSelfHostWithPath() to
 SimpleSAML\Utils\HTTP::getSelfHostWithPath() and deprecate the former.

---
 .../Metadata/MetaDataStorageHandler.php       |  2 +-
 lib/SimpleSAML/Utilities.php                  | 12 ++---------
 lib/SimpleSAML/Utils/HTTP.php                 | 20 ++++++++++++++++++-
 www/admin/hostnames.php                       |  2 +-
 4 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php
index 7ec37a88e..48c3e0470 100644
--- a/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php
+++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php
@@ -187,7 +187,7 @@ class SimpleSAML_Metadata_MetaDataStorageHandler {
 		assert('is_string($set)');
 
 		/* First we look for the hostname/path combination. */
-		$currenthostwithpath = SimpleSAML_Utilities::getSelfHostWithPath(); // sp.example.org/university
+		$currenthostwithpath = \SimpleSAML\Utils\HTTP::getSelfHostWithPath(); // sp.example.org/university
 
 		foreach($this->sources as $source) {
 			$index = $source->getEntityIdFromHostPath($currenthostwithpath, $set, $type);
diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index f315e86e7..655fcdb17 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -87,18 +87,10 @@ class SimpleSAML_Utilities {
 
 
 	/**
-	 * Will return sp.example.org/ssp/sp1
-	 *
-	 * Please note this function will return the base URL for the current
-	 * SP, as defined in the global configuration.
+	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getSelfHostWithPath() instead.
 	 */
 	public static function getSelfHostWithPath() {
-	
-		$baseurl = explode("/", self::getBaseURL());
-		$elements = array_slice($baseurl, 3 - count($baseurl), count($baseurl) - 4);
-		$path = implode("/", $elements);
-		$selfhostwithpath = self::getSelfHost();
-		return $selfhostwithpath . "/" . $path;
+		return \SimpleSAML\Utils\HTTP::getSelfHostWithPath();
 	}
 	
 	/**
diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php
index 38840c5a2..aecd23be3 100644
--- a/lib/SimpleSAML/Utils/HTTP.php
+++ b/lib/SimpleSAML/Utils/HTTP.php
@@ -319,7 +319,7 @@ class HTTP
     /**
      * Retrieve our own host.
      *
-     * @return string The current host.
+     * @return string The current host (with non-default ports included).
      *
      * @author Andreas Solberg, UNINETT AS <andreas.solberg@uninett.no>
      * @author Olav Morken, UNINETT AS <olav.morken@uninett.no>
@@ -335,6 +335,24 @@ class HTTP
     }
 
 
+    /**
+     * Retrieve our own host together with the URL path. Please note this function will return the base URL for the
+     * current SP, as defined in the global configuration.
+     *
+     * @return string The current host (with non-default ports included) plus the URL path.
+     *
+     * @author Andreas Solberg, UNINETT AS <andreas.solberg@uninett.no>
+     * @author Olav Morken, UNINETT AS <olav.morken@uninett.no>
+     */
+    public static function getSelfHostWithPath()
+    {
+        $baseurl = explode("/", self::getBaseURL());
+        $elements = array_slice($baseurl, 3 - count($baseurl), count($baseurl) - 4);
+        $path = implode("/", $elements);
+        return self::getSelfHost()."/".$path;
+    }
+
+
     /**
      * Parse a query string into an array.
      *
diff --git a/www/admin/hostnames.php b/www/admin/hostnames.php
index 90792209d..04c9a06e8 100644
--- a/www/admin/hostnames.php
+++ b/www/admin/hostnames.php
@@ -20,7 +20,7 @@ $attributes['Utilities_getBaseURL()'] = array(\SimpleSAML\Utils\HTTP::getBaseURL
 $attributes['Utilities_getSelfHost()'] = array(\SimpleSAML\Utils\HTTP::getSelfHost());
 $attributes['Utilities_selfURLhost()'] = array(SimpleSAML_Utilities::selfURLhost());
 $attributes['Utilities_selfURLNoQuery()'] = array(SimpleSAML_Utilities::selfURLNoQuery());
-$attributes['Utilities_getSelfHostWithPath()'] = array(SimpleSAML_Utilities::getSelfHostWithPath());
+$attributes['Utilities_getSelfHostWithPath()'] = array(\SimpleSAML\Utils\HTTP::getSelfHostWithPath());
 $attributes['Utilities_getFirstPathElement()'] = array(SimpleSAML_Utilities::getFirstPathElement());
 $attributes['Utilities_selfURL()'] = array(SimpleSAML_Utilities::selfURL());
 
-- 
GitLab