summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2022-07-10 01:30:05 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-07-10 23:53:02 +0300
commit1c524efbf7da91cb99bb4516feb514071e938495 (patch)
treee1fced0104749014db154f5d3b29881e705bfafc /engine
parent8979719a1af4bc0712407db7f95704f645f261a3 (diff)
dark theme support
Diffstat (limited to 'engine')
-rw-r--r--engine/RequestDispatcher.php7
-rw-r--r--engine/Skin.php5
-rw-r--r--engine/SkinContext.php8
3 files changed, 15 insertions, 5 deletions
diff --git a/engine/RequestDispatcher.php b/engine/RequestDispatcher.php
index 38b965d..3c3f684 100644
--- a/engine/RequestDispatcher.php
+++ b/engine/RequestDispatcher.php
@@ -39,11 +39,14 @@ class RequestDispatcher {
}
$skin = new Skin();
- $skin->static[] = '/css/common-bundle.css';
+ $skin->static[] = '/css/common.css';
$skin->static[] = '/js/common.js';
+ $lang = LangData::getInstance();
+ $skin->addLangKeys($lang->search('/^theme_/'));
+
/** @var RequestHandler $handler */
- $handler = new $handler_class($skin, LangData::getInstance(), $router_input);
+ $handler = new $handler_class($skin, $lang, $router_input);
$resp = $handler->beforeDispatch();
if ($resp instanceof Response) {
$resp->send();
diff --git a/engine/Skin.php b/engine/Skin.php
index 57f8b90..917eef7 100644
--- a/engine/Skin.php
+++ b/engine/Skin.php
@@ -23,11 +23,16 @@ class Skin {
else
$js = null;
+ $theme = ($_COOKIE['theme'] ?? 'auto');
+ if (!in_array($theme, ['auto', 'dark', 'light']))
+ $theme = 'auto';
+
$layout_ctx = new SkinContext('\\skin\\base');
$lang = $this->getLang();
$lang = !empty($lang) ? json_encode($lang, JSON_UNESCAPED_UNICODE) : '';
return new Response(200, $layout_ctx->layout(
static: $this->static,
+ theme: $theme,
title: $this->title,
opts: $this->options,
js: $js,
diff --git a/engine/SkinContext.php b/engine/SkinContext.php
index cfb5068..c395453 100644
--- a/engine/SkinContext.php
+++ b/engine/SkinContext.php
@@ -53,10 +53,12 @@ class SkinContext extends SkinBase {
return call_user_func_array($fn, $arguments);
}
- public function __get(string $name) {
+ public function &__get(string $name) {
$fn = $this->ns.'\\'.$name;
- if (function_exists($fn))
- return [$this, $name];
+ if (function_exists($fn)) {
+ $f = [$this, $name];
+ return $f;
+ }
if (array_key_exists($name, $this->data))
return $this->data[$name];