dbConn = $dbConn; $this->siteInfo = new SiteInfo; $this->startTemplating(); $this->contacts = new Contacts\Contacts($dbConn); $this->projects = new Projects\Projects($dbConn); $this->sshKeys = new SSHKeys\SSHKeys($dbConn); } public function getSiteInfo(): SiteInfo { return $this->siteInfo; } public function getContacts(): Contacts\Contacts { return $this->contacts; } public function getProjects(): Projects\Projects { return $this->projects; } public function getSSHKeys(): SSHKeys\SSHKeys { return $this->sshKeys; } public function getDbConn(): IDbConnection { return $this->dbConn; } public function getDbQueryCount(): int { $result = $this->dbConn->query('SHOW SESSION STATUS LIKE "Questions"'); return $result->next() ? $result->getInteger(1) : 0; } public function createMigrationManager(): DbMigrationManager { return new DbMigrationManager($this->dbConn, 'fm_' . DbMigrationManager::DEFAULT_TABLE); } public function createMigrationRepo(): IDbMigrationRepo { return new FsDbMigrationRepo(MKI_DIR_MIGRATIONS); } public function getTemplating(): SasaeEnvironment { return $this->templating; } public function startTemplating(): void { $isDebug = Environment::isDebug(); $this->templating = new SasaeEnvironment( MKI_DIR_TEMPLATES, cache: $isDebug ? null : ['Makai', GitInfo::hash(true)], debug: $isDebug, ); $this->templating->addFunction('csrfp_token', fn() => $this->getCSRFP()->createToken()); $this->templating->addGlobal('globals', [ 'siteInfo' => $this->siteInfo, 'assetsInfo' => AssetsInfo::fromCurrent(), ]); } public function getCSRFP(): CSRFP { return $this->csrfp; } public function startCSRFP(string $secretKey, string $identity): void { $this->csrfp = new CSRFP($secretKey, $identity); } public function createRouting(): RoutingContext { $routingCtx = new RoutingContext($this->templating); $routingCtx->registerDefaultErrorPages(); $routingCtx->register(new DeveloperRoutes($this->templating, $this->contacts, $this->projects)); $routingCtx->register(new AssetsRoutes($this->siteInfo)); $routingCtx->register(new Whois\WhoisRoutes($this->templating, fn() => $this->csrfp)); $routingCtx->register(new SSHKeys\SSHKeysRoutes($this->sshKeys)); $routingCtx->register(new Tools\AsciiRoutes($this->templating)); $routingCtx->register(new Tools\RandomStringRoutes); return $routingCtx; } }