/** * Frontcontroller constructor. * It performs dispatching user request and runs the controller action. * * @param Phoenix\Core\Database $db * @param Phoenix\Http\Request $request * @return void */ public function __construct(Database $db, Request $request) { $this->response = null; try { if ($db->getStatus() !== true) { throw new FailureException(FrameworkExceptions::F_DB_UNABLE_CONNECT); } $this->db = $db; $this->request = $request; $this->response_format = $this->request->getUrl()->getQueryParameter(self::URL_GET_FORMAT); $this->router = RouterFactory::createRouter(Config::get(Config::KEY_APP_USE_ROUTER)); $this->dispatch(); $this->performControllerAction(); } catch (NoticeException $e) { $this->response = ResponseFactory::createResponse($this->response_format); $this->response->setException($e); } catch (WarningException $e) { Logger::log($e, $this->db); $this->response = ResponseFactory::createResponse($this->response_format); $this->response->setException($e); } catch (FailureException $e) { Logger::log($e); $this->response = ResponseFactory::createResponse($this->response_format); $this->response->setException($e); } catch (Exception $e) { Logger::log($e); $this->response = ResponseFactory::createResponse($this->response_format); $this->response->setException($e); } }