Skip to content

Commit

Permalink
replaced my own parseQuery function with php's parse_str
Browse files Browse the repository at this point in the history
  • Loading branch information
Athlon1600 committed Sep 16, 2017
1 parent 77f67a3 commit 42c7a5e
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,33 +114,10 @@ public function getMethod(){
return $this->method;
}

// https://github.com/guzzle/psr7/blob/master/src/functions.php
// this was no longer working --- https://github.com/guzzle/psr7/blob/master/src/functions.php
public static function parseQuery($query){

$result = array();

foreach(explode('&', $query) as $kvp){
$parts = explode('=', $kvp);
$key = rawurldecode($parts[0]);
if(substr($key, -2) == '[]'){
$key = substr($key, 0, -2);
}

// keys with NULL will be ignored in http_build_query - that's why it has to be ''
$value = isset($parts[1]) ? rawurldecode($parts[1]) : '';

// brand new key=value
if(!isset($result[$key])){
$result[$key] = $value;
} else {
// key already exists in some form...
if(!is_array($result[$key])){
$result[$key] = array($result[$key]);
}

$result[$key][] = $value;
}
}
parse_str($query, $result);

return $result;
}
Expand Down

0 comments on commit 42c7a5e

Please sign in to comment.