From 0f26b054430020ec9c390aa8cd88a282dab6a3ec Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Wed, 18 Sep 2024 13:48:12 +0300 Subject: [PATCH] modules routs --- kernel/modules/admin_themes/manifest.json | 3 +- .../admin_themes/routs/adminThemes.php | 20 ++++++++++++ kernel/modules/menu/manifest.json | 3 +- kernel/modules/menu/routs/menu.php | 19 +++++++++++ kernel/modules/post/manifest.json | 3 +- kernel/modules/post/routs/post.php | 17 ++++++++++ kernel/routs/admin.php | 32 ------------------- kernel/services/ModuleService.php | 7 ++-- 8 files changed, 67 insertions(+), 37 deletions(-) create mode 100644 kernel/modules/admin_themes/routs/adminThemes.php create mode 100644 kernel/modules/menu/routs/menu.php create mode 100644 kernel/modules/post/routs/post.php diff --git a/kernel/modules/admin_themes/manifest.json b/kernel/modules/admin_themes/manifest.json index b792723..50341e3 100644 --- a/kernel/modules/admin_themes/manifest.json +++ b/kernel/modules/admin_themes/manifest.json @@ -4,5 +4,6 @@ "author": "ITGuild", "slug": "admin_themes", "description": "Admin themes module", - "module_class": "AdminThemesModule" + "module_class": "AdminThemesModule", + "routs": "routs/adminThemes.php" } \ No newline at end of file diff --git a/kernel/modules/admin_themes/routs/adminThemes.php b/kernel/modules/admin_themes/routs/adminThemes.php new file mode 100644 index 0000000..44e1110 --- /dev/null +++ b/kernel/modules/admin_themes/routs/adminThemes.php @@ -0,0 +1,20 @@ +group(["prefix" => "admin"], function (RouteCollector $router){ + App::$collector->group(["prefix" => "settings"], function (RouteCollector $router){ + App::$collector->group(["prefix" => "admin-themes"], function (RouteCollector $router){ + App::$collector->get('/', [AdminThemeController::class, 'actionIndex']); + App::$collector->get('/activate', [AdminThemeController::class, 'actionActivate']); + // App::$collector->get('/create', [\kernel\modules\menu\controllers\MenuController::class, 'actionCreate']); + // App::$collector->post("/", [\kernel\modules\menu\controllers\MenuController::class, 'actionAdd']); + // App::$collector->get('/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionView']); + // App::$collector->any('/update/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionUpdate']); + // App::$collector->any("/edit/{id}", [\kernel\modules\menu\controllers\MenuController::class, 'actionEdit']); + // App::$collector->get('/delete/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionDelete']); + }); + }); +}); \ No newline at end of file diff --git a/kernel/modules/menu/manifest.json b/kernel/modules/menu/manifest.json index c8b0d69..b8777ee 100644 --- a/kernel/modules/menu/manifest.json +++ b/kernel/modules/menu/manifest.json @@ -4,5 +4,6 @@ "author": "ITGuild", "slug": "menu", "description": "Menu module", - "module_class": "MenuModule" + "module_class": "MenuModule", + "routs": "routs/menu.php" } \ No newline at end of file diff --git a/kernel/modules/menu/routs/menu.php b/kernel/modules/menu/routs/menu.php new file mode 100644 index 0000000..14b907b --- /dev/null +++ b/kernel/modules/menu/routs/menu.php @@ -0,0 +1,19 @@ +group(["prefix" => "admin"], function (RouteCollector $router) { + App::$collector->group(["prefix" => "settings"], function (RouteCollector $router){ + App::$collector->group(["prefix" => "menu"], function (RouteCollector $router){ + App::$collector->get('/', [\kernel\modules\menu\controllers\MenuController::class, 'actionIndex']); + App::$collector->get('/page/{page_number}', [\kernel\modules\menu\controllers\MenuController::class, 'actionIndex']); + App::$collector->get('/create', [\kernel\modules\menu\controllers\MenuController::class, 'actionCreate']); + App::$collector->post("/", [\kernel\modules\menu\controllers\MenuController::class, 'actionAdd']); + App::$collector->get('/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionView']); + App::$collector->any('/update/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionUpdate']); + App::$collector->any("/edit/{id}", [\kernel\modules\menu\controllers\MenuController::class, 'actionEdit']); + App::$collector->get('/delete/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionDelete']); + }); + }); +}); \ No newline at end of file diff --git a/kernel/modules/post/manifest.json b/kernel/modules/post/manifest.json index 330d3e9..22a8180 100644 --- a/kernel/modules/post/manifest.json +++ b/kernel/modules/post/manifest.json @@ -4,5 +4,6 @@ "author": "ITGuild", "slug": "post", "description": "Post module", - "module_class": "PostModule" + "module_class": "PostModule", + "routs": "routs/post.php" } \ No newline at end of file diff --git a/kernel/modules/post/routs/post.php b/kernel/modules/post/routs/post.php new file mode 100644 index 0000000..3313e12 --- /dev/null +++ b/kernel/modules/post/routs/post.php @@ -0,0 +1,17 @@ +group(["prefix" => "admin"], function (RouteCollector $router){ + App::$collector->group(["prefix" => "post"], function (RouteCollector $router){ + App::$collector->get('/', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']); + App::$collector->get('/page/{page_number}', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']); + App::$collector->get('/create', [\kernel\modules\post\controllers\PostController::class, 'actionCreate']); + App::$collector->post("/", [\kernel\modules\post\controllers\PostController::class, 'actionAdd']); + App::$collector->get('/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionView']); + App::$collector->any('/update/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionUpdate']); + App::$collector->any("/edit/{id}", [\kernel\modules\post\controllers\PostController::class, 'actionEdit']); + App::$collector->get('/delete/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionDelete']); + }); +}); \ No newline at end of file diff --git a/kernel/routs/admin.php b/kernel/routs/admin.php index 74738b7..54b0fcb 100644 --- a/kernel/routs/admin.php +++ b/kernel/routs/admin.php @@ -11,36 +11,4 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){ App::$collector->get('/', [\kernel\controllers\ModuleController::class, 'actionIndex']); App::$collector->get('/activate', [\kernel\controllers\ModuleController::class, 'actionActivate']); }); - App::$collector->group(["prefix" => "post"], function (RouteCollector $router){ - App::$collector->get('/', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']); - App::$collector->get('/page/{page_number}', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']); - App::$collector->get('/create', [\kernel\modules\post\controllers\PostController::class, 'actionCreate']); - App::$collector->post("/", [\kernel\modules\post\controllers\PostController::class, 'actionAdd']); - App::$collector->get('/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionView']); - App::$collector->any('/update/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionUpdate']); - App::$collector->any("/edit/{id}", [\kernel\modules\post\controllers\PostController::class, 'actionEdit']); - App::$collector->get('/delete/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionDelete']); - }); - App::$collector->group(["prefix" => "settings"], function (RouteCollector $router){ - App::$collector->group(["prefix" => "menu"], function (RouteCollector $router){ - App::$collector->get('/', [\kernel\modules\menu\controllers\MenuController::class, 'actionIndex']); - App::$collector->get('/page/{page_number}', [\kernel\modules\menu\controllers\MenuController::class, 'actionIndex']); - App::$collector->get('/create', [\kernel\modules\menu\controllers\MenuController::class, 'actionCreate']); - App::$collector->post("/", [\kernel\modules\menu\controllers\MenuController::class, 'actionAdd']); - App::$collector->get('/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionView']); - App::$collector->any('/update/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionUpdate']); - App::$collector->any("/edit/{id}", [\kernel\modules\menu\controllers\MenuController::class, 'actionEdit']); - App::$collector->get('/delete/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionDelete']); - }); - App::$collector->group(["prefix" => "admin-themes"], function (RouteCollector $router){ - App::$collector->get('/', [AdminThemeController::class, 'actionIndex']); - App::$collector->get('/activate', [AdminThemeController::class, 'actionActivate']); -// App::$collector->get('/create', [\kernel\modules\menu\controllers\MenuController::class, 'actionCreate']); -// App::$collector->post("/", [\kernel\modules\menu\controllers\MenuController::class, 'actionAdd']); -// App::$collector->get('/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionView']); -// App::$collector->any('/update/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionUpdate']); -// App::$collector->any("/edit/{id}", [\kernel\modules\menu\controllers\MenuController::class, 'actionEdit']); -// App::$collector->get('/delete/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionDelete']); - }); - }); }); \ No newline at end of file diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php index d9d0364..095d958 100644 --- a/kernel/services/ModuleService.php +++ b/kernel/services/ModuleService.php @@ -77,6 +77,7 @@ class ModuleService { $modules = []; $module_paths = Option::where("key", "module_paths")->first(); + $active_modules = Option::where("key", "active_modules")->first(); $dirs = []; if ($module_paths) { $path = json_decode($module_paths->value); @@ -85,13 +86,15 @@ class ModuleService } } + $active_modules = json_decode($active_modules->value, true); + foreach ($dirs as $dir) { foreach (new DirectoryIterator($dir) as $fileInfo) { - if($fileInfo->isDot()) continue; + if($fileInfo->isDot() or !in_array($fileInfo->getFilename(), $active_modules['modules'])) continue; $modules[] = $this->getModuleInfo($fileInfo->getPathname()); } } - + return $modules; }