Symfony\Component\HttpFoundation\Request::overrideGlobals PHP Method

overrideGlobals() public method

It overrides $_GET, $_POST, $_REQUEST, $_SERVER, $_COOKIE. $_FILES is never overridden, see rfc1867
public overrideGlobals ( )
    public function overrideGlobals()
    {
        $this->server->set('QUERY_STRING', static::normalizeQueryString(http_build_query($this->query->all(), null, '&')));

        $_GET = $this->query->all();
        $_POST = $this->request->all();
        $_SERVER = $this->server->all();
        $_COOKIE = $this->cookies->all();

        foreach ($this->headers->all() as $key => $value) {
            $key = strtoupper(str_replace('-', '_', $key));
            if (in_array($key, array('CONTENT_TYPE', 'CONTENT_LENGTH'))) {
                $_SERVER[$key] = implode(', ', $value);
            } else {
                $_SERVER['HTTP_'.$key] = implode(', ', $value);
            }
        }

        $request = array('g' => $_GET, 'p' => $_POST, 'c' => $_COOKIE);

        $requestOrder = ini_get('request_order') ?: ini_get('variables_order');
        $requestOrder = preg_replace('#[^cgp]#', '', strtolower($requestOrder)) ?: 'gp';

        $_REQUEST = array();
        foreach (str_split($requestOrder) as $order) {
            $_REQUEST = array_merge($_REQUEST, $request[$order]);
        }
    }

Usage Example

 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     if ($type !== self::MASTER_REQUEST) {
         throw new \LogicException('Wordpress\\HttpKernel cannot handle SUB_REQUESTS');
     }
     unset($type);
     $this->catch = $catch;
     unset($catch);
     $this->timezone = date_default_timezone_get();
     $this->startOutputBuffer();
     try {
         $wp_the_query = null;
         $this->storeGlobals();
         $request->overrideGlobals();
         if ($globalNames = @(include $this->wordpressGlobalNamesCacheFile)) {
             foreach ($globalNames ?: array() as $name) {
                 @eval('global $' . $name . ';');
             }
         } else {
             throw new \RuntimeException('The global names cache file has to be generated with "app/console startplatz:wordpress-integration:build-global-names-cache"');
         }
         define('WP_USE_THEMES', true);
         $time_start = microtime(true);
         require_once "{$this->wordpressRootDir}/wp-load.php";
         global $wp_query;
         $wp_query = $wp_the_query;
         \wp();
         require_once "{$this->wordpressRootDir}/wp-includes/template-loader.php";
         $content = $this->endOutputBuffer();
         $statusCode = is_404() ? 404 : 200;
         $headers = $this->flushHeaders();
         $this->restoreGlobals();
         date_default_timezone_set($this->timezone);
         return new Response($content, $statusCode, $headers);
     } catch (\Exception $e) {
         $this->endOutputBuffer();
         $this->flushHeaders();
         $this->restoreGlobals();
         date_default_timezone_set($this->timezone);
         if ($this->catch) {
             return new Response($e->getMessage(), 500);
         } else {
             throw $e;
         }
     }
 }
All Usage Examples Of Symfony\Component\HttpFoundation\Request::overrideGlobals