2016-02-28 15 views
0

我試圖在php中製作一個最簡單和非常基本的請求響應系統,類似於Yii-2.0。對於我的基本\網絡\的index.php裏面讀書有:在請求 - 響應過程中,當運行Yii -2.0應用程序時會發生什麼()?

$application = new yii\web\Application($config); 
$application->run(); 

我挖越深,但是這個過程是如何進行的無法弄清楚。

以下是我發現:

在警予\網絡\應用run()方法有這個(不包括觸發器):

$response = $this->handleRequest($this->getRequest()); 
$response->send(); 
return $response->exitStatus; 

的handleRequest只是一個抽象的函數呢,

abstract public function handleRequest($request); 

所以我基本上不明白這段代碼是如何返回響應的?

UPDATE

如這裏回答是快速referene的handleRequest功能:

public function handleRequest($request) 
    { 
     if (empty($this->catchAll)) { 
      list ($route, $params) = $request->resolve(); 
     } else { 
      $route = $this->catchAll[0]; 
      $params = $this->catchAll; 
      unset($params[0]); 
     } 
     try { 
      Yii::trace("Route requested: '$route'", __METHOD__); 
      $this->requestedRoute = $route; 
      $result = $this->runAction($route, $params); 
      if ($result instanceof Response) { 
       return $result; 
      } else { 
       $response = $this->getResponse(); 
       if ($result !== null) { 
        $response->data = $result; 
       } 
       return $response; 
      } 
     } catch (InvalidRouteException $e) { 
      throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'), $e->getCode(), $e); 
     } 
    } 

我是在一個過程中找出的全過程。只要我全力以赴,我會盡快回復。我們可能會比Yii文檔製作更好的流程圖。 :)

回答

相關問題