예제 #1
0
 private static function startDispatch()
 {
     $buffering = !IN_CLI && self::$outputBuffer;
     if ($buffering) {
         ob_start();
     }
     try {
         self::dispatch();
         $controllerPath = self::$request->getControllerPath();
         $actionFile = self::$request->getActionFile();
     } catch (Exception $e) {
         if (IN_CLI) {
             throw $e;
             return;
         }
         $controllerPath = 'error';
         self::$request->setUserParam('exception', $e);
         $controller = new ErrorController();
         if ($e instanceof PageNotFoundException) {
             $actionFile = 'page-not-found';
             self::$response->setHttpResponseCode(404);
             $controller->pageNotFoundAction();
         } else {
             $actionFile = 'internal-error';
             self::$response->setHttpResponseCode(500);
             $controller->internalErrorAction();
         }
     }
     if (self::$shouldRender && !self::$response->isRedirect()) {
         self::$view->render($controllerPath, $actionFile);
     }
     if ($buffering && !self::$response->isRedirect()) {
         self::$response->setBody(ob_get_clean());
     }
     self::$response->sendResponse();
 }