mirror of
https://github.com/openvk/openvk
synced 2025-07-07 08:19:49 +03:00
Replace Themepacks
Code reformat.
This commit is contained in:
parent
e2141d17af
commit
a2c32fa097
1 changed files with 48 additions and 54 deletions
|
@ -1,18 +1,21 @@
|
||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace openvk\Web\Themes;
|
namespace openvk\Web\Themes;
|
||||||
|
|
||||||
use Nette\InvalidStateException as ISE;
|
use Nette\InvalidStateException as ISE;
|
||||||
use Chandler\Session\Session;
|
use Chandler\Session\Session;
|
||||||
use Chandler\Patterns\TSimpleSingleton;
|
use Chandler\Patterns\TSimpleSingleton;
|
||||||
|
|
||||||
class Themepacks implements \ArrayAccess
|
class Themepacks implements \ArrayAccess {
|
||||||
{
|
|
||||||
const THEMPACK_ENGINE_VERSION = 1;
|
const THEMPACK_ENGINE_VERSION = 1;
|
||||||
const DEFAULT_THEME_ID = "ovk"; # блин было бы смешно если было бы Fore, потому что Лунка, а Luna это название дефолт темы винхп
|
const DEFAULT_THEME_ID = "ovk"; # блин было бы смешно если было бы Fore, потому что Лунка, а Luna это название дефолт темы винхп
|
||||||
|
|
||||||
private $loadedThemepacks = [];
|
private $loadedThemepacks = [];
|
||||||
|
|
||||||
function __construct()
|
function __construct() {
|
||||||
{
|
|
||||||
foreach (glob(OPENVK_ROOT . "/themepacks/*", GLOB_ONLYDIR) as $themeDir) {
|
foreach (glob(OPENVK_ROOT . "/themepacks/*", GLOB_ONLYDIR) as $themeDir) {
|
||||||
try {
|
try {
|
||||||
$theme = Themepack::themepackFromDir($themeDir);
|
$theme = Themepack::themepackFromDir($themeDir);
|
||||||
|
@ -27,8 +30,7 @@ class Themepacks implements \ArrayAccess
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function installUnpacked(string $path): bool
|
private function installUnpacked(string $path): bool {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
$theme = Themepack::themepackFromDir($path);
|
$theme = Themepack::themepackFromDir($path);
|
||||||
$tid = $theme->getId();
|
$tid = $theme->getId();
|
||||||
|
@ -43,44 +45,37 @@ class Themepacks implements \ArrayAccess
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getThemeList(): \Traversable
|
function getThemeList(): \Traversable {
|
||||||
{
|
|
||||||
foreach ($this->loadedThemepacks as $id => $theme)
|
foreach ($this->loadedThemepacks as $id => $theme)
|
||||||
if ($theme->isEnabled())
|
if ($theme->isEnabled())
|
||||||
yield $id => ($theme->getName(Session::i()->get("lang", "ru")));
|
yield $id => ($theme->getName(Session::i()->get("lang", "ru")));
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAllThemes(): array
|
function getAllThemes(): array {
|
||||||
{
|
|
||||||
return $this->loadedThemepacks;
|
return $this->loadedThemepacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ArrayAccess */
|
/* ArrayAccess */
|
||||||
|
|
||||||
function offsetExists($offset): bool
|
function offsetExists($offset): bool {
|
||||||
{
|
|
||||||
return $offset === Themepacks::DEFAULT_THEME_ID ? false : isset($this->loadedThemepacks[$offset]);
|
return $offset === Themepacks::DEFAULT_THEME_ID ? false : isset($this->loadedThemepacks[$offset]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function offsetGet($offset)
|
function offsetGet($offset) {
|
||||||
{
|
|
||||||
return $this->loadedThemepacks[$offset];
|
return $this->loadedThemepacks[$offset];
|
||||||
}
|
}
|
||||||
|
|
||||||
function offsetSet($offset, $value): void
|
function offsetSet($offset, $value): void {
|
||||||
{
|
|
||||||
throw new ISE("Theme substitution in runtime is prohbited");
|
throw new ISE("Theme substitution in runtime is prohbited");
|
||||||
}
|
}
|
||||||
|
|
||||||
function offsetUnset($offset): void
|
function offsetUnset($offset): void {
|
||||||
{
|
|
||||||
$this->uninstall($offset);
|
$this->uninstall($offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* /ArrayAccess */
|
/* /ArrayAccess */
|
||||||
|
|
||||||
function install(string $archivePath): bool
|
function install(string $archivePath): bool {
|
||||||
{
|
|
||||||
if (!file_exists($archivePath))
|
if (!file_exists($archivePath))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -97,8 +92,7 @@ class Themepacks implements \ArrayAccess
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function uninstall(string $id): bool
|
function uninstall(string $id): bool {
|
||||||
{
|
|
||||||
if (!isset($loadedThemepacks[$id]))
|
if (!isset($loadedThemepacks[$id]))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -108,4 +102,4 @@ class Themepacks implements \ArrayAccess
|
||||||
}
|
}
|
||||||
|
|
||||||
use TSimpleSingleton;
|
use TSimpleSingleton;
|
||||||
}
|
} // Я рыгнул
|
Loading…
Reference in a new issue