config = $config; } public function connectDb(?IDbConnection $dbConn = null): void { $dbConn ??= DbTools::create($this->config->getValue('database:dsn', IConfig::T_STR, 'null')); $dbConn->execute(self::DB_INIT); $this->dbConn = $dbConn; } public function getDb(): IDbConnection { return $this->dbConn; } public function getDbQueryCount(): int { $result = $this->dbConn->query('SHOW SESSION STATUS LIKE "Questions"'); return $result->next() ? $result->getInteger(0) : 0; } public function setUpHttp(): void { $this->router = new HttpFx; $this->router->use('/', function($response) { $response->setPoweredBy('Hanyuu'); }); $this->registerErrorPages(); $this->registerHttpRoutes(); } public function dispatchHttp(?HttpRequest $request = null): void { $this->router->dispatch($request); } private function registerErrorPages(): void { /*$this->router->addErrorHandler(400, function($response) { $response->setContent(Template::renderRaw('errors.400')); }); $this->router->addErrorHandler(403, function($response) { $response->setContent(Template::renderRaw('errors.403')); }); $this->router->addErrorHandler(404, function($response) { $response->setContent(Template::renderRaw('errors.404')); }); $this->router->addErrorHandler(500, function($response) { $response->setContent(file_get_contents(MSZ_TEMPLATES . '/500.html')); }); $this->router->addErrorHandler(503, function($response) { $response->setContent(file_get_contents(MSZ_TEMPLATES . '/503.html')); });*/ } private function registerHttpRoutes(): void { $this->router->get('/', function($response, $request) { $siteName = $this->config->getValue('site:name', IConfig::T_STR, 'Hanyuu'); return "\r\n" . "{$siteName} ID\r\n" . "
\r\n" . "

Under Construction

\r\n" . " \"\"/\r\n" . "
\r\n"; }); } }