default theme
This commit is contained in:
@ -2,11 +2,15 @@
|
||||
|
||||
namespace kernel\services;
|
||||
|
||||
use DirectoryIterator;
|
||||
use kernel\helpers\Manifest;
|
||||
use kernel\helpers\RESTClient;
|
||||
use kernel\models\Option;
|
||||
|
||||
class ThemeService
|
||||
{
|
||||
protected array $errors = [];
|
||||
|
||||
protected Option $option;
|
||||
protected string $active_theme = "";
|
||||
|
||||
@ -16,6 +20,23 @@ class ThemeService
|
||||
$this->findActiveTheme();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getErrors(): array
|
||||
{
|
||||
return $this->errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $msg
|
||||
* @return void
|
||||
*/
|
||||
public function addError($msg): void
|
||||
{
|
||||
$this->errors[] = $msg;
|
||||
}
|
||||
|
||||
public function findActiveTheme(): void
|
||||
{
|
||||
$model = $this->option::where("key", "active_theme")->first();
|
||||
@ -27,16 +48,16 @@ class ThemeService
|
||||
return $this->active_theme;
|
||||
}
|
||||
|
||||
public function getThemeRout(string $path)
|
||||
public function setActiveTheme(string $theme): void
|
||||
{
|
||||
if (file_exists($path . "/manifest.json")){
|
||||
$manifest = json_decode(file_get_contents($path . "/manifest.json"), true);
|
||||
if ($manifest['routs']) {
|
||||
return $manifest['routs'];
|
||||
}
|
||||
}
|
||||
$activeTheme = Option::where("key", "active_theme")->first();
|
||||
$activeTheme->value = getConst($theme);
|
||||
$activeTheme->save();
|
||||
}
|
||||
|
||||
return false;
|
||||
public function getActiveThemeInfo(): false|array|string
|
||||
{
|
||||
return $this->getThemeInfo($this->active_theme);
|
||||
}
|
||||
|
||||
public function getThemeInfo(string $theme): false|array|string
|
||||
@ -54,11 +75,44 @@ class ThemeService
|
||||
return $info;
|
||||
}
|
||||
|
||||
public function setActiveTheme(string $theme): void
|
||||
public function getThemeInfoBySlug(string $slug): false|array|string
|
||||
{
|
||||
$activeTheme = Option::where("key", "active_theme")->first();
|
||||
$activeTheme->value = getConst($theme);
|
||||
$activeTheme->save();
|
||||
$dirs = $this->getThemeDirs();
|
||||
foreach ($dirs as $dir) {
|
||||
foreach (new DirectoryIterator($dir) as $fileInfo) {
|
||||
if ($fileInfo->isDot()) continue;
|
||||
if ($this->getThemeInfo($fileInfo->getPathname())['slug'] === $slug) {
|
||||
return $this->getThemeInfo($fileInfo->getPathname());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getThemeDirs(): array
|
||||
{
|
||||
$ThemePaths = Option::where("key", "theme_paths")->first();
|
||||
$dirs = [];
|
||||
if ($ThemePaths) {
|
||||
$path = json_decode($ThemePaths->value);
|
||||
foreach ($path->paths as $p) {
|
||||
$dirs[] = getConst($p);
|
||||
}
|
||||
}
|
||||
return $dirs;
|
||||
}
|
||||
|
||||
public function getThemeRout(string $path)
|
||||
{
|
||||
if (file_exists($path . "/manifest.json")){
|
||||
$manifest = json_decode(file_get_contents($path . "/manifest.json"), true);
|
||||
if ($manifest['routs']) {
|
||||
return $manifest['routs'];
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user