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

---
 lib/SimpleSAML/Configuration.php |  2 +-
 lib/SimpleSAML/Utilities.php     | 13 +++++--------
 lib/SimpleSAML/Utils/HTTP.php    | 18 ++++++++++++++++++
 www/admin/hostnames.php          |  2 +-
 4 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/lib/SimpleSAML/Configuration.php b/lib/SimpleSAML/Configuration.php
index 88faf0276..85d697503 100644
--- a/lib/SimpleSAML/Configuration.php
+++ b/lib/SimpleSAML/Configuration.php
@@ -346,7 +346,7 @@ class SimpleSAML_Configuration {
 		
 		if (preg_match('/^\*(.*)$/D', $baseURL, $matches)) {
 			/* deprecated behaviour, will be removed in the future */
-			return SimpleSAML_Utilities::getFirstPathElement(false) . $matches[1];
+			return \SimpleSAML\Utils\HTTP::getFirstPathElement(false) . $matches[1];
 		}
 
 		if (preg_match('#^https?://[^/]*/(.*)$#', $baseURL, $matches)) {
diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index 655fcdb17..df9e6c163 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -92,18 +92,15 @@ class SimpleSAML_Utilities {
 	public static function getSelfHostWithPath() {
 		return \SimpleSAML\Utils\HTTP::getSelfHostWithPath();
 	}
-	
+
+
 	/**
-	 * Will return foo
+	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getFirstPathElement() instead.
 	 */
 	public static function getFirstPathElement($trailingslash = true) {
-	
-		if (preg_match('|^/(.*?)/|', $_SERVER['SCRIPT_NAME'], $matches)) {
-			return ($trailingslash ? '/' : '') . $matches[1];
-		}
-		return '';
+		return \SimpleSAML\Utils\HTTP::getFirstPathElement($trailingslash);
 	}
-	
+
 
 	public static function selfURL() {
 
diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php
index aecd23be3..1a170fccf 100644
--- a/lib/SimpleSAML/Utils/HTTP.php
+++ b/lib/SimpleSAML/Utils/HTTP.php
@@ -316,6 +316,24 @@ class HTTP
     }
 
 
+    /**
+     * Retrieve the first element of the URL path.
+     *
+     * @param boolean $trailingslash Whether to add a trailing slash to the element or not. Defaults to true.
+     *
+     * @return string The first element of the URL path, with an optional, trailing slash.
+     *
+     * @author Andreas Solberg, UNINETT AS <andreas.solberg@uninett.no>
+     */
+    public static function getFirstPathElement($trailingslash = true)
+    {
+        if (preg_match('|^/(.*?)/|', $_SERVER['SCRIPT_NAME'], $matches)) {
+            return ($trailingslash ? '/' : '').$matches[1];
+        }
+        return '';
+    }
+
+
     /**
      * Retrieve our own host.
      *
diff --git a/www/admin/hostnames.php b/www/admin/hostnames.php
index 04c9a06e8..6839055cc 100644
--- a/www/admin/hostnames.php
+++ b/www/admin/hostnames.php
@@ -21,7 +21,7 @@ $attributes['Utilities_getSelfHost()'] = array(\SimpleSAML\Utils\HTTP::getSelfHo
 $attributes['Utilities_selfURLhost()'] = array(SimpleSAML_Utilities::selfURLhost());
 $attributes['Utilities_selfURLNoQuery()'] = array(SimpleSAML_Utilities::selfURLNoQuery());
 $attributes['Utilities_getSelfHostWithPath()'] = array(\SimpleSAML\Utils\HTTP::getSelfHostWithPath());
-$attributes['Utilities_getFirstPathElement()'] = array(SimpleSAML_Utilities::getFirstPathElement());
+$attributes['Utilities_getFirstPathElement()'] = array(\SimpleSAML\Utils\HTTP::getFirstPathElement());
 $attributes['Utilities_selfURL()'] = array(SimpleSAML_Utilities::selfURL());
 
 $et = new SimpleSAML_XHTML_Template($config, 'hostnames.php');
-- 
GitLab