File tree Expand file tree Collapse file tree 4 files changed +36
-20
lines changed
resources/stubs/template/src/Helpers Expand file tree Collapse file tree 4 files changed +36
-20
lines changed Original file line number Diff line number Diff line change 1- vendor /
2- .idea /
3- build /
1+ vendor
2+ .idea
3+ .vscode
4+ build
45.DS_Store
5- * .cache
6+ * .cache
Original file line number Diff line number Diff line change 1010|
1111*/
1212
13- if (! function_exists ('theme_load ' )) {
14-
15- /**
16- * This function is called on theme loading. Put in all the rules that
17- * you want to be executedas a settings override or any other action.
18- */
19- function theme_load ()
20- {
21- // Unleash your imagination here
22- }
23- }
24-
2513if (! function_exists ('theme_inspire ' )) {
2614
2715 /**
Original file line number Diff line number Diff line change 77use Codions \ThemesManager \Events \ThemeEnabled ;
88use Codions \ThemesManager \Events \ThemeEnabling ;
99use Codions \ThemesManager \Facades \ThemesManager ;
10+ use Codions \ThemesManager \Traits \Autoloader ;
1011use Codions \ThemesManager \Traits \HasConfigs ;
1112use Codions \ThemesManager \Traits \HasHelpers ;
1213use Codions \ThemesManager \Traits \HasTranslations ;
@@ -24,6 +25,7 @@ class Theme
2425 use HasViews;
2526 use HasHelpers;
2627 use HasConfigs;
28+ use Autoloader;
2729
2830 /**
2931 * The theme name.
@@ -196,6 +198,14 @@ public function getVendor(): string
196198 return $ this ->vendor ;
197199 }
198200
201+ public function getNamespace (string $ path = null ): string
202+ {
203+ $ vendor = Str::studly ($ this ->vendor );
204+ $ name = Str::studly ($ this ->name );
205+
206+ return "Themes \\$ vendor \\$ name \\" . $ path ;
207+ }
208+
199209 /**
200210 * Check if has parent Theme.
201211 */
@@ -275,14 +285,11 @@ public function enable(bool $withEvent = true): self
275285 }
276286
277287 $ this ->enabled = true ;
288+ $ this ->registerAutoloader ();
278289 $ this ->loadViews ();
279290 $ this ->loadTranlastions ();
280291 $ this ->loadHelpers ();
281292
282- if (function_exists ('theme_load ' )) {
283- theme_load ();
284- }
285-
286293 if ($ withEvent ) {
287294 event (new ThemeEnabled ($ this ->name ));
288295 }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Codions \ThemesManager \Traits ;
4+
5+ trait Autoloader
6+ {
7+ public function registerAutoloader ()
8+ {
9+ spl_autoload_register (function ($ class ) {
10+ $ class = str_replace ($ this ->getNamespace (), '' , $ class );
11+
12+ $ class = str_replace ('\\' , DIRECTORY_SEPARATOR , $ class );
13+ $ file = $ this ->getPath ("src/ {$ class }.php " );
14+
15+ if (file_exists ($ file )) {
16+ require_once $ file ;
17+ }
18+ });
19+ }
20+ }
You can’t perform that action at this time.
0 commit comments