v2.0-alpha
This commit is contained in:
@@ -5,8 +5,9 @@ namespace Elements;
|
||||
use Configuration\Settings;
|
||||
use Driver\Logger\Logger;
|
||||
use Driver\SQL\SQL;
|
||||
use Objects\Context;
|
||||
use Objects\Router\Router;
|
||||
use Objects\User;
|
||||
use Objects\DatabaseEntity\User;
|
||||
|
||||
abstract class Document {
|
||||
|
||||
@@ -32,16 +33,20 @@ abstract class Document {
|
||||
return $this->logger;
|
||||
}
|
||||
|
||||
public function getUser(): User {
|
||||
return $this->router->getUser();
|
||||
public function getUser(): ?User {
|
||||
return $this->getContext()->getUser();
|
||||
}
|
||||
|
||||
public function getContext(): Context {
|
||||
return $this->router->getContext();
|
||||
}
|
||||
|
||||
public function getSQL(): ?SQL {
|
||||
return $this->getUser()->getSQL();
|
||||
return $this->getContext()->getSQL();
|
||||
}
|
||||
|
||||
public function getSettings(): Settings {
|
||||
return $this->getUser()->getConfiguration()->getSettings();
|
||||
return $this->getContext()->getSettings();
|
||||
}
|
||||
|
||||
public function getCSPNonce(): ?string {
|
||||
|
||||
@@ -65,10 +65,10 @@ class HtmlDocument extends Document {
|
||||
}
|
||||
|
||||
$head = $this->head->getCode();
|
||||
$lang = $this->getUser()->getLanguage()->getShortCode();
|
||||
$lang = $this->getContext()->getLanguage();
|
||||
|
||||
$code = "<!DOCTYPE html>";
|
||||
$code .= html_tag("html", ["lang" => $lang], $head . $body, false);
|
||||
$code .= html_tag("html", ["lang" => $lang->getShortCode()], $head . $body, false);
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
@@ -46,13 +46,14 @@ class TemplateDocument extends Document {
|
||||
public function renderTemplate(string $name, array $params = []): string {
|
||||
try {
|
||||
|
||||
$user = $this->getUser();
|
||||
$context = $this->getContext();
|
||||
$session = $context->getSession();
|
||||
$params["user"] = [
|
||||
"lang" => $user->getLanguage()->getShortCode(),
|
||||
"loggedIn" => $user->isLoggedIn(),
|
||||
"session" => (!$user->isLoggedIn() ? null : [
|
||||
"csrfToken" => $user->getSession()->getCsrfToken()
|
||||
])
|
||||
"lang" => $context->getLanguage()->getShortCode(),
|
||||
"loggedIn" => $session !== null,
|
||||
"session" => ($session ? [
|
||||
"csrfToken" => $session->getCsrfToken()
|
||||
] : null)
|
||||
];
|
||||
|
||||
$settings = $this->getSettings();
|
||||
|
||||
@@ -23,8 +23,7 @@ abstract class View extends StaticView {
|
||||
public function isSearchable(): bool { return $this->searchable; }
|
||||
|
||||
public function getSiteName(): string {
|
||||
// what a chain lol
|
||||
return $this->getDocument()->getUser()->getConfiguration()->getSettings()->getSiteName();
|
||||
return $this->getDocument()->getSettings()->getSiteName();
|
||||
}
|
||||
|
||||
protected function load(string $viewClass) : string {
|
||||
@@ -43,7 +42,7 @@ abstract class View extends StaticView {
|
||||
}
|
||||
|
||||
private function loadLanguageModules() {
|
||||
$lang = $this->document->getUser()->getLanguage();
|
||||
$lang = $this->document->getContext()->getLanguage();
|
||||
foreach ($this->langModules as $langModule) {
|
||||
$lang->loadModule($langModule);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user