File tree Expand file tree Collapse file tree 3 files changed +36
-4
lines changed
Expand file tree Collapse file tree 3 files changed +36
-4
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 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,6 +285,7 @@ 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 ();
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