Swoole\Request::setGlobal PHP Method

setGlobal() public method

将原始请求信息转换到PHP超全局变量中
public setGlobal ( )
    function setGlobal()
    {
        /**
         * 将HTTP头信息赋值给$_SERVER超全局变量
         */
        foreach ($this->header as $key => $value) {
            $_key = 'HTTP_' . strtoupper(str_replace('-', '_', $key));
            $this->server[$_key] = $value;
        }
        $_GET = $this->get;
        $_POST = $this->post;
        $_FILES = $this->files;
        $_COOKIE = $this->cookie;
        $_SERVER = $this->server;
        $this->request = $_REQUEST = array_merge($this->get, $this->post, $this->cookie);
    }

Usage Example

 function onRequest(Swoole\Request $request)
 {
     $response = new Swoole\Response();
     $php = Swoole::getInstance();
     $request->setGlobal();
     //        if($this->doStaticRequest($request, $response))
     //        {
     //            return $response;
     //        }
     //将对象赋值到控制器
     $php->request = $request;
     $php->response = $response;
     $response->head['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0';
     $response->head['Pragma'] = 'no-cache';
     try {
         ob_start();
         /*---------------------处理MVC----------------------*/
         $response->body = $php->runMVC();
         $response->body .= ob_get_contents();
         ob_end_clean();
     } catch (\Exception $e) {
         if ($request->finish != 1) {
             $this->http_error(404, $response, $e->getMessage());
         }
     }
     if (!isset($response->head['Content-Type'])) {
         $response->head['Content-Type'] = 'text/html; charset=' . $this->config['apps']['charset'];
     }
     //重定向
     if (isset($response->head['Location'])) {
         $response->send_http_status(301);
     }
     return $response;
 }
All Usage Examples Of Swoole\Request::setGlobal