1 | <?php |
||
23 | class ThemeManager extends \yii\base\Component |
||
24 | { |
||
25 | /** |
||
26 | * Name of the event before the active theme will be setup. |
||
27 | */ |
||
28 | const EVENT_BEFORE_SETUP = 'eventBeforeSetup'; |
||
29 | |||
30 | /** |
||
31 | * Name of the theme which should be activated on setup. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | public $activeThemeName; |
||
36 | |||
37 | /** |
||
38 | * @var ThemeConfig[] |
||
39 | */ |
||
40 | private $_themes = []; |
||
41 | |||
42 | /** |
||
43 | * Read the theme.json and create a new \luya\theme\ThemeConfig for the given base path. |
||
44 | * |
||
45 | * @param string $basePath |
||
46 | * |
||
47 | * @return ThemeConfig |
||
48 | * @throws Exception |
||
49 | * @throws InvalidConfigException |
||
50 | */ |
||
51 | protected static function loadThemeConfig(string $basePath) |
||
74 | |||
75 | /** |
||
76 | * Setup active theme |
||
77 | * |
||
78 | * @throws Exception |
||
79 | * @throws InvalidConfigException |
||
80 | * @throws \yii\db\Exception |
||
81 | */ |
||
82 | final public function setup() |
||
98 | |||
99 | /** |
||
100 | * Trigger the {{\luya\theme\ThemeManager::EVENT_BEFORE_SETUP}} event. |
||
101 | * |
||
102 | * @param string $basePath |
||
103 | */ |
||
104 | protected function beforeSetup(string &$basePath) |
||
112 | |||
113 | /** |
||
114 | * Get base path of active theme. |
||
115 | * |
||
116 | * @return string |
||
117 | * @throws \yii\db\Exception |
||
118 | */ |
||
119 | protected function getActiveThemeBasePath() |
||
127 | |||
128 | /** |
||
129 | * Get all theme configs as array list. |
||
130 | * |
||
131 | * @return ThemeConfig[] |
||
132 | * @throws Exception |
||
133 | * @throws InvalidConfigException |
||
134 | */ |
||
135 | public function getThemes() |
||
150 | |||
151 | /** |
||
152 | * Get theme definitions by search in `@app/themes` and the `Yii::$app->getPackageInstaller()` |
||
153 | * |
||
154 | * @return string[] |
||
155 | */ |
||
156 | protected function getThemeDefinitions() |
||
173 | |||
174 | /** |
||
175 | * @param string $basePath |
||
176 | * |
||
177 | * @return ThemeConfig |
||
178 | * @throws Exception |
||
179 | * @throws InvalidConfigException |
||
180 | */ |
||
181 | public function getThemeByBasePath(string $basePath) |
||
191 | |||
192 | /** |
||
193 | * Register a theme config and set the path alias with the name of the theme. |
||
194 | * |
||
195 | * @param ThemeConfig $themeConfig Base path of the theme. |
||
196 | * |
||
197 | * @throws InvalidConfigException |
||
198 | */ |
||
199 | protected function registerTheme(ThemeConfig $themeConfig) |
||
210 | |||
211 | /** |
||
212 | * Change the active theme in the \yii\base\View component and set the `activeTheme ` alias to new theme base path. |
||
213 | * |
||
214 | * @param Theme $theme |
||
215 | */ |
||
216 | protected function activate(Theme $theme) |
||
223 | |||
224 | /** |
||
225 | * @var Theme|null |
||
226 | */ |
||
227 | private $_activeTheme; |
||
228 | |||
229 | /** |
||
230 | * Get the active theme. Null if no theme is activated. |
||
231 | * |
||
232 | * @return Theme|null |
||
233 | */ |
||
234 | public function getActiveTheme() |
||
238 | |||
239 | /** |
||
240 | * Change the active theme. |
||
241 | * |
||
242 | * @param Theme $theme |
||
243 | */ |
||
244 | protected function setActiveTheme(Theme $theme) |
||
248 | |||
249 | /** |
||
250 | * Check if a theme is activated. |
||
251 | * |
||
252 | * @return bool |
||
253 | */ |
||
254 | public function getHasActiveTheme() |
||
258 | } |
||
259 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: