Преглед изворни кода

[HttpKernel] added Request::getUri()

Fabien Potencier пре 15 година
родитељ
комит
287f787927
1 измењених фајлова са 33 додато и 0 уклоњено
  1. 33 0
      src/Symfony/Components/HttpKernel/Request.php

+ 33 - 0
src/Symfony/Components/HttpKernel/Request.php

@@ -268,6 +268,39 @@ class Request
         return $this->requestUri;
     }
 
+    /**
+     * 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
+     */
+    public function getUri()
+    {
+        $parts = $this->getScheme().'://'.$this->getHost().':'.$this->getPort().$this->getScriptName().$this->getPathInfo();
+
+        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);
+
+            $elements = array();
+            foreach ($parts as $key => $value) {
+                $elements[] = "$key=$value";
+            }
+
+            if (count($elements)) {
+                $parts .= '?'.implode('&', $elements);
+            }
+        }
+
+        return $parts;
+    }
+
     public function isSecure()
     {
         return (