Ver código fonte

[HttpKernel] added Request::overrideGlobals()

Fabien Potencier 15 anos atrás
pai
commit
632ef95e06
1 arquivos alterados com 18 adições e 0 exclusões
  1. 18 0
      src/Symfony/Components/HttpKernel/Request.php

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

@@ -184,6 +184,24 @@ class Request
         $this->headers = clone $this->headers;
     }
 
+    /**
+     * Overrides the PHP global variables according to this request instance.
+     *
+     * It overrides $_GET, $_POST, $_REQUEST, $_SERVER, $_COOKIES, and $_FILES.
+     */
+    public function overrideGlobals()
+    {
+        $_GET = $this->query->all();
+        $_POST = $this->request->all();
+        $_SERVER = $this->server->all();
+        $_COOKIES = $this->cookies->all();
+        // FIXME: populate $_FILES
+
+        // FIXME: should read variables_order and request_order
+        // to know which globals to merge and in which order
+        $_REQUEST = array_merge($_GET, $_POST);
+    }
+
     // Order of precedence: GET, PATH, POST, COOKIE
     // Avoid using this method in controllers:
     //  * slow