summaryrefslogtreecommitdiffstats
path: root/lib/SimpleSAML/Utils/HTTP.php
diff options
context:
space:
mode:
authorJaime Perez Crespo <jaime.perez@uninett.no>2015-04-21 11:31:03 +0200
committerJaime Perez Crespo <jaime.perez@uninett.no>2015-04-21 11:31:03 +0200
commit1e079f45adf97fee458965183f1d4b6845970079 (patch)
treebe3c024a5daf81061c2767fad2380046057b3441 /lib/SimpleSAML/Utils/HTTP.php
parentfaf91600a945de38c52e32a4b4f8871c7814b6cf (diff)
downloadsimplesamlphp-1e079f45adf97fee458965183f1d4b6845970079.zip
simplesamlphp-1e079f45adf97fee458965183f1d4b6845970079.tar.gz
simplesamlphp-1e079f45adf97fee458965183f1d4b6845970079.tar.bz2
Move SimpleSAML_Utilities::addURLparameter() to SimpleSAML\Utils\HTTP::addURLParameters() and deprecate the former.
Diffstat (limited to 'lib/SimpleSAML/Utils/HTTP.php')
-rw-r--r--lib/SimpleSAML/Utils/HTTP.php42
1 files changed, 41 insertions, 1 deletions
diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php
index d501162..bf7ac0c 100644
--- a/lib/SimpleSAML/Utils/HTTP.php
+++ b/lib/SimpleSAML/Utils/HTTP.php
@@ -66,6 +66,46 @@ class HTTP
/**
+ * Add one or more query parameters to the given URL.
+ *
+ * @param string $url The URL the query parameters should be added to.
+ * @param array $parameters The query parameters which should be added to the url. This should be an associative
+ * array.
+ *
+ * @return string The URL with the new query parameters.
+ * @throws \SimpleSAML_Error_Exception If $url is not a string or $parameters is not an array.
+ *
+ * @author Andreas Solberg, UNINETT AS <andreas.solberg@uninett.no>
+ * @author Olav Morken, UNINETT AS <olav.morken@uninett.no>
+ */
+ public static function addURLParameters($url, $parameters)
+ {
+ if (!is_string($url) || !is_array($parameters)) {
+ throw new \SimpleSAML_Error_Exception('Invalid input parameters.');
+ }
+
+ $queryStart = strpos($url, '?');
+ if ($queryStart === false) {
+ $oldQuery = array();
+ $url .= '?';
+ } else {
+ $oldQuery = substr($url, $queryStart + 1);
+ if ($oldQuery === false) {
+ $oldQuery = array();
+ } else {
+ $oldQuery = self::parseQueryString($oldQuery);
+ }
+ $url = substr($url, 0, $queryStart + 1);
+ }
+
+ $query = array_merge($oldQuery, $parameters);
+ $url .= http_build_query($query, '', '&');
+
+ return $url;
+ }
+
+
+ /**
* Retrieve the port number from $_SERVER environment variables.
*
* @return string The port number prepended by a colon, if it is different than the default port for the protocol
@@ -107,7 +147,7 @@ class HTTP
public static function parseQueryString($query_string)
{
if (!is_string($query_string)) {
- throw new \SimpleSAML_Error_Exception('Invalid input parameters');
+ throw new \SimpleSAML_Error_Exception('Invalid input parameters.');
}
$res = array();