Ubiquity
2.5.2
php rapid development framework
Loading...
Searching...
No Matches
ThemesManager.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Ubiquity\themes
;
4
5
use
Ubiquity\controllers\Startup
;
6
use
Ubiquity\domains\DDDManager
;
7
use
Ubiquity\events\EventsManager
;
8
use
Ubiquity\events\ViewEvents
;
9
use
Ubiquity\exceptions\ThemesException
;
10
use
Ubiquity\views\engine\twig\Twig
;
11
22
class
ThemesManager
{
23
const
THEMES_FOLDER
=
'themes'
;
24
private
static
$activeTheme
;
25
private
static
$refThemes
= [
'bootstrap'
,
'foundation'
,
'semantic'
];
26
27
public
static
function
getActiveTheme
() {
28
return
self::$activeTheme
;
29
}
30
37
public
static
function
setActiveTheme
(
string
$activeTheme
): void {
38
self::
$activeTheme
=
$activeTheme
??
''
;
39
$engineInstance = Startup::$templateEngine;
40
if
($engineInstance instanceof
Twig
) {
41
$engineInstance->setTheme(
$activeTheme
, self::THEMES_FOLDER);
42
}
else
{
43
throw
new
ThemesException
(
'Template engine must be an instance of Twig for themes activation!'
);
44
}
45
}
46
47
public
static
function
saveActiveTheme
(
string
$theme): array {
48
$config =
Startup
::getConfig();
49
$config [
'templateEngineOptions'
] [
'activeTheme'
] = $theme;
50
Startup::saveConfig($config);
51
return
$config;
52
}
53
59
public
static
function
setActiveThemeFromTwig
(
string
$activeTheme) {
60
self::$activeTheme = $activeTheme;
61
}
62
68
public
static
function
getAvailableThemes
(): array {
69
$path =
DDDManager
::getActiveViewFolder() . self::THEMES_FOLDER . \DS .
'*'
;
70
$dirs = \glob($path, GLOB_ONLYDIR | GLOB_NOSORT);
71
$result = [];
72
foreach
($dirs as $dir) {
73
$result [] = \basename($dir);
74
}
75
return
$result;
76
}
77
83
public
static
function
getRefThemes
(): array {
84
return self::$refThemes;
85
}
86
93
public
static
function
isCustom
(
string
$theme): bool {
94
return \array_search($theme, self::$refThemes) === false;
95
}
96
102
public
static
function
getNotInstalledThemes
(): array {
103
$AvailableThemes = self::getAvailableThemes();
104
return \array_diff(self::$refThemes, $AvailableThemes);
105
}
106
113
public
static
function
onBeforeRender
($callback) {
114
EventsManager::addListener(ViewEvents::BEFORE_RENDER, $callback);
115
}
116
123
public
static
function
onAfterRender
($callback) {
124
EventsManager::addListener(ViewEvents::AFTER_RENDER, $callback);
125
}
126
}
Ubiquity\controllers\Startup
Starts the framework.
Definition
Startup.php:19
Ubiquity\domains\DDDManager
Manager for a Domain Driven Design approach.
Definition
DDDManager.php:20
Ubiquity\events\EventsManager
Manage events.
Definition
EventsManager.php:16
Ubiquity\events\ViewEvents
View events constants.
Definition
ViewEvents.php:15
Ubiquity\exceptions\ThemesException
Exceptions for ThemesManager.
Definition
ThemesException.php:15
Ubiquity\themes\ThemesManager
Themes manager.
Definition
ThemesManager.php:22
Ubiquity\themes\ThemesManager\setActiveTheme
static setActiveTheme(string $activeTheme)
Sets the activeTheme.
Definition
ThemesManager.php:37
Ubiquity\themes\ThemesManager\getAvailableThemes
static getAvailableThemes()
Returns the names of available themes.
Definition
ThemesManager.php:68
Ubiquity\themes\ThemesManager\setActiveThemeFromTwig
static setActiveThemeFromTwig(string $activeTheme)
Sets the activeTheme.
Definition
ThemesManager.php:59
Ubiquity\themes\ThemesManager\THEMES_FOLDER
const THEMES_FOLDER
Definition
ThemesManager.php:23
Ubiquity\themes\ThemesManager\getActiveTheme
static getActiveTheme()
Definition
ThemesManager.php:27
Ubiquity\themes\ThemesManager\onAfterRender
static onAfterRender($callback)
Adds a listener after theme rendering.
Definition
ThemesManager.php:123
Ubiquity\themes\ThemesManager\onBeforeRender
static onBeforeRender($callback)
Adds a listener before theme rendering.
Definition
ThemesManager.php:113
Ubiquity\themes\ThemesManager\isCustom
static isCustom(string $theme)
Returns if a theme is a custom Theme (not in refThemes).
Definition
ThemesManager.php:93
Ubiquity\themes\ThemesManager\getRefThemes
static getRefThemes()
Returns all referenced themes.
Definition
ThemesManager.php:83
Ubiquity\themes\ThemesManager\$activeTheme
static $activeTheme
Definition
ThemesManager.php:24
Ubiquity\themes\ThemesManager\$refThemes
static $refThemes
Definition
ThemesManager.php:25
Ubiquity\themes\ThemesManager\getNotInstalledThemes
static getNotInstalledThemes()
Returns the not installed themes.
Definition
ThemesManager.php:102
Ubiquity\themes\ThemesManager\saveActiveTheme
static saveActiveTheme(string $theme)
Definition
ThemesManager.php:47
Ubiquity\views\engine\twig\Twig
Ubiquity Twig template engine.
Definition
Twig.php:31
Ubiquity\themes
Definition
ThemesManager.php:3
C:
Users
myadd
Documents
GitHub
ubiquity-doc-api
vendor
phpmv
ubiquity
src
Ubiquity
themes
ThemesManager.php
Generated on Sun Dec 10 2023 15:04:25 for
Ubiquity
by
doxygen
1.9.8