flash.moe/src/MakaiContext.php

87 lines
2.6 KiB
PHP
Raw Normal View History

<?php
namespace Makai;
2023-10-12 18:45:11 +00:00
use Index\Environment;
use Index\Data\IDbConnection;
2023-10-12 18:45:11 +00:00
use Sasae\SasaeEnvironment;
final class MakaiContext {
2023-10-12 18:45:11 +00:00
private IDbConnection $dbConn;
2023-10-12 22:09:04 +00:00
private SasaeEnvironment $templating;
private SiteInfo $siteInfo;
private Contacts\Contacts $contacts;
private Projects\Projects $projects;
private SSHKeys\SSHKeys $sshKeys;
2023-10-12 18:45:11 +00:00
public function __construct(IDbConnection $dbConn) {
$this->dbConn = $dbConn;
2023-10-12 22:09:04 +00:00
$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 getDatabase(): IDbConnection {
2023-10-12 18:45:11 +00:00
return $this->dbConn;
}
2023-10-12 22:09:04 +00:00
public function getSiteInfo(): SiteInfo {
return $this->siteInfo;
}
2023-10-12 22:09:04 +00:00
public function getContacts(): Contacts\Contacts {
return $this->contacts;
}
2023-10-12 22:09:04 +00:00
public function getProjects(): Projects\Projects {
return $this->projects;
}
2023-10-12 22:09:04 +00:00
public function getSSHKeys(): SSHKeys\SSHKeys {
return $this->sshKeys;
}
2023-10-12 22:09:04 +00:00
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->addGlobal('globals', [
'siteInfo' => $this->siteInfo,
2023-10-13 19:33:34 +00:00
'assetsInfo' => AssetsInfo::fromCurrent(),
2023-10-12 22:09:04 +00:00
]);
}
public function createRouting(): RoutingContext {
$routingCtx = new RoutingContext($this->templating);
$routingCtx->registerDefaultErrorPages();
$routingCtx->register(new HomeRoutes($this->templating, $this->contacts, $this->projects));
$routingCtx->register(new Contacts\ContactsRoutes($this->templating, $this->contacts));
$routingCtx->register(new Projects\ProjectsRoutes($this->templating, $this->projects));
$routingCtx->register(new AssetsRoutes($this->siteInfo));
$routingCtx->register(new NowListeningRoutes($this->templating));
$routingCtx->register(new Whois\WhoisRoutes($this->templating));
$routingCtx->register(new SSHKeys\SSHKeysRoutes($this->sshKeys));
$routingCtx->register(new Tools\AsciiRoutes($this->templating));
$routingCtx->register(new Tools\RandomStringRoutes);
return $routingCtx;
}
}