Skip to content

Commit

Permalink
[HttpKernel] added Request::getQueryString()
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed May 10, 2010
1 parent 287f787 commit 6536204
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions src/Symfony/Components/HttpKernel/Request.php
Expand Up @@ -271,34 +271,50 @@ public function getRequestUri()
/**
* Generates a normalized URI for the Request.
*
* It builds a normalized query string, where keys/value pairs are alphabetized
* and have consistent escaping.
*
* @return string A normalized URI for the Request
*
* @see getQueryString()
*/
public function getUri()
{
$parts = $this->getScheme().'://'.$this->getHost().':'.$this->getPort().$this->getScriptName().$this->getPathInfo();
$qs = $this->getQueryString();
if (null !== $qs)
{
$qs = '?'.$qs;
}

if ($qs = $this->server->get('QUERY_STRING')) {
$parts = array();
foreach (explode('&', $qs) as $segment) {
$tmp = explode('=', urldecode($segment), 2);
$parts[urlencode($tmp[0])] = urlencode($tmp[1]);
}
ksort($parts);
return $this->getScheme().'://'.$this->getHost().':'.$this->getPort().$this->getScriptName().$this->getPathInfo().$qs;
}

$elements = array();
foreach ($parts as $key => $value) {
$elements[] = "$key=$value";
}
/**
* Generates the normalized query string for the Request.
*
* It builds a normalized query string, where keys/value pairs are alphabetized
* and have consistent escaping.
*
* @return string A normalized query string for the Request
*/
public function getQueryString()
{
if (!$qs = $this->server->get('QUERY_STRING')) {
return null;
}

if (count($elements)) {
$parts .= '?'.implode('&', $elements);
}
$parts = array();
foreach (explode('&', $qs) as $segment) {
$tmp = explode('=', urldecode($segment), 2);
$parts[urlencode($tmp[0])] = urlencode($tmp[1]);
}
ksort($parts);

return $parts;
$elements = array();
foreach ($parts as $key => $value) {
$elements[] = "$key=$value";
}

if (count($elements)) {
return implode('&', $elements);
}
}

public function isSecure()
Expand Down

1 comment on commit 6536204

@marijn
Copy link

@marijn marijn commented on 6536204 Jun 20, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use http_build_query?

Please sign in to comment.