module routing
This commit is contained in:
parent
f48d6753e2
commit
f20ba63277
8
app/modules/tag/manifest.json
Normal file
8
app/modules/tag/manifest.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "Tags",
|
||||
"version": "0.1",
|
||||
"author": "ITGuild",
|
||||
"slug": "tag",
|
||||
"description": "Tags module",
|
||||
"module_class": "TagModule"
|
||||
}
|
@ -4,6 +4,8 @@ namespace kernel;
|
||||
|
||||
|
||||
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\services\ModuleService;
|
||||
use Phroute\Phroute\Dispatcher;
|
||||
|
||||
class App
|
||||
@ -15,6 +17,8 @@ class App
|
||||
|
||||
static Header $header;
|
||||
|
||||
public ModuleService $moduleService;
|
||||
|
||||
public static Database $db;
|
||||
|
||||
public function run(): void
|
||||
@ -29,6 +33,7 @@ class App
|
||||
|
||||
public function load(): static
|
||||
{
|
||||
$this->moduleService = new ModuleService();
|
||||
App::$collector = new CgRouteCollector();
|
||||
$this->setRouting();
|
||||
|
||||
@ -39,6 +44,10 @@ class App
|
||||
{
|
||||
include KERNEL_DIR . "/routs/admin.php";
|
||||
include ROOT_DIR . "/rout.php";
|
||||
$modules_routs = $this->moduleService->getModulesRouts();
|
||||
foreach ($modules_routs as $rout){
|
||||
include "$rout";
|
||||
}
|
||||
}
|
||||
|
||||
public static function create(): App
|
||||
|
@ -4,5 +4,6 @@
|
||||
"author": "ITGuild",
|
||||
"slug": "user",
|
||||
"description": "User module",
|
||||
"module_class": "UserModule"
|
||||
"module_class": "UserModule",
|
||||
"routs": "routs/user.php"
|
||||
}
|
@ -21,16 +21,6 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
|
||||
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" => "user"], callback: function (RouteCollector $router){
|
||||
App::$collector->get('/', [\kernel\modules\user\controllers\UserController::class, 'actionIndex']);
|
||||
App::$collector->get('/page/{page_number}', [\kernel\modules\user\controllers\UserController::class, 'actionIndex']);
|
||||
App::$collector->get('/create', [\kernel\modules\user\controllers\UserController::class, 'actionCreate']);
|
||||
App::$collector->post("/", [\kernel\modules\user\controllers\UserController::class, 'actionAdd']);
|
||||
App::$collector->get('/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionView']);
|
||||
App::$collector->any('/update/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionUpdate']);
|
||||
App::$collector->any("/edit/{id}", [\kernel\modules\user\controllers\UserController::class, 'actionEdit']);
|
||||
App::$collector->get('/delete/{id}', [\kernel\modules\user\controllers\UserController::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']);
|
||||
|
@ -14,7 +14,7 @@ class ModuleService
|
||||
{
|
||||
$info = [];
|
||||
$info['path'] = $module;
|
||||
if (file_exists($module . "/manifest.json")){
|
||||
if (file_exists($module . "/manifest.json")) {
|
||||
$manifest = file_get_contents($module . "/manifest.json");
|
||||
$manifest = Manifest::getWithVars($manifest);
|
||||
$info = array_merge($info, $manifest);
|
||||
@ -26,10 +26,10 @@ class ModuleService
|
||||
public function isActive(string $slug): bool
|
||||
{
|
||||
$active_modules = Option::where("key", "active_modules")->first();
|
||||
if ($active_modules){
|
||||
if ($active_modules) {
|
||||
$path = json_decode($active_modules->value);
|
||||
foreach ($path->modules as $p){
|
||||
if ($p === $slug){
|
||||
foreach ($path->modules as $p) {
|
||||
if ($p === $slug) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -56,16 +56,16 @@ class ModuleService
|
||||
{
|
||||
$module_paths = Option::where("key", "module_paths")->first();
|
||||
$dirs = [];
|
||||
if ($module_paths){
|
||||
if ($module_paths) {
|
||||
$path = json_decode($module_paths->value);
|
||||
foreach ($path->paths as $p){
|
||||
foreach ($path->paths as $p) {
|
||||
$dirs[] = getConst($p);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($dirs as $dir){
|
||||
foreach ($dirs as $dir) {
|
||||
foreach (new DirectoryIterator($dir) as $fileInfo) {
|
||||
if(basename($fileInfo->getPathname()) === $slug) {
|
||||
if (basename($fileInfo->getPathname()) === $slug) {
|
||||
return $fileInfo->getPathname();
|
||||
}
|
||||
}
|
||||
@ -73,4 +73,39 @@ class ModuleService
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getActiveModules(): array
|
||||
{
|
||||
$modules = [];
|
||||
$module_paths = Option::where("key", "module_paths")->first();
|
||||
$dirs = [];
|
||||
if ($module_paths) {
|
||||
$path = json_decode($module_paths->value);
|
||||
foreach ($path->paths as $p) {
|
||||
$dirs[] = getConst($p);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($dirs as $dir) {
|
||||
foreach (new DirectoryIterator($dir) as $fileInfo) {
|
||||
if($fileInfo->isDot()) continue;
|
||||
$modules[] = $this->getModuleInfo($fileInfo->getPathname());
|
||||
}
|
||||
}
|
||||
|
||||
return $modules;
|
||||
}
|
||||
|
||||
public function getModulesRouts(): array
|
||||
{
|
||||
$routs = [];
|
||||
$modules = $this->getActiveModules();
|
||||
foreach ($modules as $module){
|
||||
if (isset($module['routs'])){
|
||||
$routs[] = $module['path'] . "/" . $module['routs'];
|
||||
}
|
||||
}
|
||||
|
||||
return $routs;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user