Example #1
0
 /**
  * Handle the request and dispatch to routes.
  *
  * @param $request
  *
  * @throws Exception|\Exception
  *
  * @return array|ResponseInterface|mixed|static
  *
  *
  * @note this function is incomplete, need to enhance
  * for better exception handling
  */
 public function handle($request)
 {
     $this->setRouter($this->app->compose('Cygnite\\Base\\Router\\Router', $request), $request);
     try {
         $response = $this->sendRequestThroughRouter($request);
         /*
          * Check whether return value is a instance of Response,
          * otherwise we will try to fetch the response form container,
          * create a response and return to the browser.
          *
          */
         if (!$response instanceof ResponseInterface && !is_array($response)) {
             $r = $this->app->has('response') ? $this->app->get('response') : '';
             $response = Response::make($r);
         }
     } catch (\Exception $e) {
         $this->handleException($e);
     } catch (Throwable $e) {
         $this->handleException($e);
     }
     return $response;
 }