diff options
author | Jaime Perez Crespo <jaime.perez@uninett.no> | 2015-04-21 11:12:14 +0200 |
---|---|---|
committer | Jaime Perez Crespo <jaime.perez@uninett.no> | 2015-04-21 11:12:14 +0200 |
commit | faf91600a945de38c52e32a4b4f8871c7814b6cf (patch) | |
tree | 232d4e20f611cd22c708bc8b15bd7c03b3a18084 /lib/SimpleSAML/Utils/HTTP.php | |
parent | 3703d50a76ed5ec1aea85ab4a4b10ac1ef10c9d2 (diff) | |
download | simplesamlphp-faf91600a945de38c52e32a4b4f8871c7814b6cf.zip simplesamlphp-faf91600a945de38c52e32a4b4f8871c7814b6cf.tar.gz simplesamlphp-faf91600a945de38c52e32a4b4f8871c7814b6cf.tar.bz2 |
Move SimpleSAML_Utilities::parseQueryString() to SimpleSAML\Utils\HTTP::parseQueryString() and deprecate the former.
Diffstat (limited to 'lib/SimpleSAML/Utils/HTTP.php')
-rw-r--r-- | lib/SimpleSAML/Utils/HTTP.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php index 01a6209..d501162 100644 --- a/lib/SimpleSAML/Utils/HTTP.php +++ b/lib/SimpleSAML/Utils/HTTP.php @@ -87,4 +87,40 @@ class HTTP } return $port; } + + + /** + * Parse a query string into an array. + * + * This function parses a query string into an array, similar to the way the builtin 'parse_str' works, except it + * doesn't handle arrays, and it doesn't do "magic quotes". + * + * Query parameters without values will be set to an empty string. + * + * @param string $query_string The query string which should be parsed. + * + * @return array The query string as an associative array. + * @throws \SimpleSAML_Error_Exception If $query_string is not a string. + * + * @author Olav Morken, UNINETT AS <olav.morken@uninett.no> + */ + public static function parseQueryString($query_string) + { + if (!is_string($query_string)) { + throw new \SimpleSAML_Error_Exception('Invalid input parameters'); + } + + $res = array(); + foreach (explode('&', $query_string) as $param) { + $param = explode('=', $param); + $name = urldecode($param[0]); + if (count($param) === 1) { + $value = ''; + } else { + $value = urldecode($param[1]); + } + $res[$name] = $value; + } + return $res; + } }
\ No newline at end of file |