2025-01-15 15:00:30 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace kernel\services;
|
|
|
|
|
2025-01-15 16:57:03 +03:00
|
|
|
use kernel\helpers\Manifest;
|
2025-01-15 15:00:30 +03:00
|
|
|
use kernel\models\Option;
|
|
|
|
|
|
|
|
class ThemeService
|
|
|
|
{
|
|
|
|
protected Option $option;
|
|
|
|
protected string $active_theme = "";
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->option = new Option();
|
2025-01-15 16:57:03 +03:00
|
|
|
$this->findActiveTheme();
|
2025-01-15 15:00:30 +03:00
|
|
|
}
|
|
|
|
|
2025-01-15 16:57:03 +03:00
|
|
|
public function findActiveTheme(): void
|
2025-01-15 15:00:30 +03:00
|
|
|
{
|
|
|
|
$model = $this->option::where("key", "active_theme")->first();
|
|
|
|
$this->active_theme = $model->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getActiveTheme(): string
|
|
|
|
{
|
|
|
|
return $this->active_theme;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2025-01-15 16:57:03 +03:00
|
|
|
public function getThemeInfo(string $theme): false|array|string
|
|
|
|
{
|
|
|
|
$info = [];
|
|
|
|
$theme = getConst($theme);
|
|
|
|
$info['path'] = $theme;
|
|
|
|
if (file_exists($theme . "/manifest.json")) {
|
|
|
|
$manifest = file_get_contents($theme . "/manifest.json");
|
|
|
|
$manifest = Manifest::getWithVars($manifest);
|
|
|
|
$manifest['preview'] = $manifest['resource'] . "/" . $manifest['preview'];
|
|
|
|
$info = array_merge($info, $manifest);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $info;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setActiveTheme(string $theme): void
|
|
|
|
{
|
|
|
|
$activeTheme = Option::where("key", "active_theme")->first();
|
|
|
|
$activeTheme->value = getConst($theme);
|
|
|
|
$activeTheme->save();
|
|
|
|
}
|
|
|
|
|
2025-01-15 15:00:30 +03:00
|
|
|
}
|