Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
ThemesManager.php
Go to the documentation of this file.
1<?php
2
4
11
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}
Starts the framework.
Definition Startup.php:19
Manager for a Domain Driven Design approach.
View events constants.
Exceptions for ThemesManager.
static setActiveTheme(string $activeTheme)
Sets the activeTheme.
static getAvailableThemes()
Returns the names of available themes.
static setActiveThemeFromTwig(string $activeTheme)
Sets the activeTheme.
static onAfterRender($callback)
Adds a listener after theme rendering.
static onBeforeRender($callback)
Adds a listener before theme rendering.
static isCustom(string $theme)
Returns if a theme is a custom Theme (not in refThemes).
static getRefThemes()
Returns all referenced themes.
static getNotInstalledThemes()
Returns the not installed themes.
static saveActiveTheme(string $theme)
Ubiquity Twig template engine.
Definition Twig.php:31