@@ -16,9 +16,9 @@ class Admin {
1616 /**
1717 * @var array<string, DashboardInterface>
1818 */
19- public array $ dashboards = [];
19+ private array $ dashboards = [];
2020
21- public function __construct (Template $ template ) {
21+ public function __construct (private readonly Template $ template ) {
2222 foreach (Config::get ('dashboards ' , []) as $ class ) {
2323 if (is_subclass_of ($ class , DashboardInterface::class) && $ class ::check ()) {
2424 $ dashboard = new $ class ($ template );
@@ -28,13 +28,45 @@ public function __construct(Template $template) {
2828 }
2929 }
3030
31- public function getDashboard (string $ dashboard ): DashboardInterface {
31+ private function getDashboard (string $ dashboard ): DashboardInterface {
3232 return $ this ->dashboards [$ dashboard ];
3333 }
3434
35- public function currentDashboard (): string {
35+ private function currentDashboard (): string {
3636 $ current = Http::get ('dashboard ' , '' );
3737
3838 return array_key_exists ($ current , $ this ->dashboards ) ? $ current : array_key_first ($ this ->dashboards );
3939 }
40+
41+ public function render (bool $ auth ): string {
42+ $ nav = array_map (static fn ($ d_dashboard ): array => $ d_dashboard ->dashboardInfo (), $ this ->dashboards );
43+
44+ $ current = $ this ->currentDashboard ();
45+ $ dashboard = $ this ->getDashboard ($ current );
46+ $ info = $ dashboard ->dashboardInfo ();
47+
48+ $ this ->template ->addGlobal ('current ' , $ current );
49+
50+ if (isset ($ _GET ['ajax ' ])) {
51+ return $ dashboard ->ajax ();
52+ }
53+
54+ $ colors = '' ;
55+
56+ if (isset ($ info ['colors ' ])) {
57+ foreach ((array ) $ info ['colors ' ] as $ key => $ color ) {
58+ $ colors .= '--color-primary- ' .$ key .': ' .$ color .'; ' ;
59+ }
60+ }
61+
62+ return $ this ->template ->render ('layout ' , [
63+ 'colors ' => $ colors ,
64+ 'site_title ' => $ info ['title ' ],
65+ 'nav ' => $ nav ,
66+ 'logout_url ' => $ auth ? Http::queryString ([], ['logout ' => 'yes ' ]) : null ,
67+ 'version ' => self ::VERSION ,
68+ 'repo ' => 'https://github.com/RobiNN1/phpCacheAdmin ' ,
69+ 'dashboard ' => $ dashboard ->dashboard (),
70+ ]);
71+ }
4072}
0 commit comments